Skip to content

Commit 0362ef2

Browse files
committed
Substitute ^ for cross product Vec2D
1 parent 0ebef24 commit 0362ef2

File tree

6 files changed

+173
-3
lines changed

6 files changed

+173
-3
lines changed

demo/circles.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env jruby
12
require 'picrate'
23

34
class Circles < Processing::App

demo/library/circle/lib/t_points.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def <<(pt)
2020
end
2121

2222
def collinear?
23-
full? ? (positions[0] - positions[1]).cross(positions[1] - positions[2]).zero? : false
23+
full? ? ((positions[0] - positions[1]) ^ (positions[1] - positions[2])).zero? : false
2424
end
2525

2626
# returns positions as an array of Vec2D

library/vecmath/vec2d/library/circle/lib/points.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def <<(pt)
2121

2222
def collinear?
2323
return false unless full?
24-
(array[0] - array[1]).cross(array[1] - array[2]).zero?
24+
((array[0] - array[1]) ^ (array[1] - array[2])).zero?
2525
end
2626

2727
def array

library/vecmath/vec2d/library/circles/lib/t_points.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def <<(pt)
2020
end
2121

2222
def collinear?
23-
full? ? (positions[0] - positions[1]).cross(positions[1] - positions[2]).zero? : false
23+
full? ? ((positions[0] - positions[1]) ^ (positions[1] - positions[2])).zero? : false
2424
end
2525

2626
# returns positions as an array of Vec2D

shaders/data/sigmoids.glsl

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#ifdef GL_ES
2+
precision mediump float;
3+
precision mediump int;
4+
#endif
5+
6+
// From a shadertoy sketch by Victor Shepardson
7+
// https://www.shadertoy.com/view/ltfXzj
8+
9+
uniform vec3 iResolution; // viewport resolution (in pixels)
10+
uniform float iTime; // shader playback time (in seconds)
11+
12+
const float pi = 3.14159;
13+
14+
float sigmoid(float x){
15+
return x/(1.+abs(x));
16+
}
17+
18+
float iter(vec2 p, vec4 a, vec4 wt, vec4 ws, float t, float m, float stereo){
19+
float wp = .2;
20+
vec4 phase = vec4(mod(t, wp), mod(t+wp*.25, wp), mod(t+wp*.5, wp), mod(t+wp*.75, wp))/wp;
21+
float zoom = 1./(1.+.5*(p.x*p.x+p.y*p.y));
22+
vec4 scale = zoom*pow(vec4(2.), -4.*phase);
23+
vec4 ms = .5-.5*cos(2.*pi*phase);
24+
vec4 pan = stereo/scale*(1.-phase)*(1.-phase);
25+
vec4 v = ms*sin( wt*(t+m) + (m+ws*scale)*((p.x+pan) * cos((t+m)*a) + p.y * sin((t+m)*a)));
26+
return sigmoid(v.x+v.y+v.z+v.w+m);
27+
}
28+
29+
vec3 scene(float gt, vec2 uv, vec4 a0, vec4 wt0, vec4 ws0, float blur){
30+
//time modulation
31+
float tm = mod(.0411*gt, 1.);
32+
tm = sin(2.*pi*tm*tm);
33+
float t = (.04*gt + .05*tm);
34+
35+
float stereo = 1.*(sigmoid(2.*(sin(1.325*t*cos(.5*t))+sin(-.7*t*sin(.77*t)))));//+sin(-17.*t)+sin(10.*t))));
36+
//t = 0.;
37+
//also apply spatial offset
38+
uv+= .5*sin(.33*t)*vec2(cos(t), sin(t));
39+
40+
//wildly iterate and divide
41+
float p0 = iter(uv, a0, wt0, ws0, t, 0., stereo);
42+
43+
float p1 = iter(uv, a0, wt0, ws0, t, p0, stereo);
44+
45+
float p2 = sigmoid(p0/(p1+blur));
46+
47+
float p3 = iter(uv, a0, wt0, ws0, t, p2, stereo);
48+
49+
float p4 = sigmoid(p3/(p2+blur));
50+
51+
float p5 = iter(uv, a0, wt0, ws0, t, p4, stereo);
52+
53+
float p6 = sigmoid(p4/(p5+blur));
54+
55+
float p7 = iter(uv, a0, wt0, ws0, t, p6, stereo);
56+
57+
float p8 = sigmoid(p4/(p2+blur));
58+
59+
float p9 = sigmoid(p8/(p7+blur));
60+
61+
float p10 = iter(uv, a0, wt0, ws0, t, p8, stereo);
62+
63+
float p11 = iter(uv, a0, wt0, ws0, t, p9, stereo);
64+
65+
float p12 = sigmoid(p11/(p10+blur));
66+
67+
float p13 = iter(uv, a0, wt0, ws0, t, p12, stereo);
68+
69+
//colors
70+
vec3 accent_color = vec3(1.,0.2,0.);//vec3(0.99,0.5,0.2);
71+
/*float r = sigmoid(-1.+2.*p0+p1-max(1.*p3,0.)+p5+p7+p10+p11+p13);
72+
float g = sigmoid(-1.+2.*p0-max(1.*p1,0.)-max(2.*p3,0.)-max(2.*p5,0.)+p7+p10+p11+p13);
73+
float b = sigmoid(0.+1.5*p0+p1+p3+-max(2.*p5,0.)+p7+p10+p11+p13);
74+
*/
75+
float r = sigmoid(p0+p1+p5+p7+p10+p11+p13);
76+
float g = sigmoid(p0-p1+p3+p7+p10+p11);
77+
float b = sigmoid(p0+p1+p3+p5+p11+p13);
78+
79+
80+
vec3 c = max(vec3(0.), .4+.6*vec3(r,g,b));
81+
82+
float eps = .4;
83+
float canary = min(abs(p1), abs(p2));
84+
canary = min(canary, abs(p5));
85+
//canary = min(canary, abs(p6));
86+
canary = min(canary, abs(p7));
87+
canary = min(canary, abs(p10));
88+
float m = max(0.,eps-canary)/eps;
89+
m = sigmoid((m-.5)*700./(1.+10.*blur))*.5+.5;
90+
//m = m*m*m*m*m*m*m*m*m*m;
91+
vec3 m3 = m*(1.-accent_color);
92+
c *= .8*(1.-m3)+.3;//mix(c, vec3(0.), m);
93+
94+
return c;
95+
}
96+
97+
void main( void )
98+
{
99+
float s = min(iResolution.x, iResolution.y);
100+
vec2 uv = (2.*gl_FragCoord.xy - vec2(iResolution.xy)) / s;
101+
102+
float blur = .5*(uv.x*uv.x+uv.y*uv.y);
103+
104+
//angular, spatial and temporal frequencies
105+
vec4 a0 = pi*vec4(.1, -.11, .111, -.1111);
106+
vec4 wt0 = 2.*pi*vec4(.3);//.3333, .333, .33, .3);
107+
vec4 ws0 = 2.5*vec4(11., 13., 11., 5.);
108+
109+
//aa and motion blur
110+
float mb = 1.;
111+
float t = 1100.+iTime;
112+
vec3 c = scene(t, uv, a0, wt0, ws0, blur)
113+
+ scene(t-mb*.00185, uv+(1.+blur)*vec2(.66/s, 0.), a0, wt0, ws0, blur)
114+
+ scene(t-mb*.00370, uv+(1.+blur)*vec2(-.66/s, 0.), a0, wt0, ws0, blur)
115+
+ scene(t-mb*.00555, uv+(1.+blur)*vec2(0., .66/s), a0, wt0, ws0, blur)
116+
+ scene(t-mb*.00741, uv+(1.+blur)*vec2(0., -.66/s), a0, wt0, ws0, blur)
117+
+ scene(t-mb*.00926, uv+(1.+blur)*vec2(.5/s, .5/s), a0, wt0, ws0, blur)
118+
+ scene(t-mb*.01111, uv+(1.+blur)*vec2(-.5/s, .5/s), a0, wt0, ws0, blur)
119+
+ scene(t-mb*.01296, uv+(1.+blur)*vec2(-.5/s, -.5/s), a0, wt0, ws0, blur)
120+
+ scene(t-mb*.01481, uv+(1.+blur)*vec2(.5/s, -.5/s), a0, wt0, ws0, blur)
121+
122+
;
123+
c/=9.;
124+
125+
gl_FragColor = vec4(c,1.0);
126+
}

shaders/sigmoids.rb

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env jruby
2+
# frozen_string_literal: true
3+
require 'picrate'
4+
5+
class Sigmoids < Processing::App
6+
7+
attr_reader :previous_time, :wrapper, :start
8+
# Shader by Victor Shepardson
9+
10+
def settings
11+
size(800, 450, P2D)
12+
end
13+
14+
def setup
15+
sketch_title 'Sigmoids n sine (by Victor Shepardson)'
16+
@previous_time = 0.0
17+
@mouse_dragged = false
18+
@mouse_click_state = 0.0
19+
@wrapper = load_shader(data_path('sigmoids.glsl'))
20+
# Assume the dimension of the window will not change over time
21+
wrapper.set('iResolution', width.to_f, height.to_f, 0.0)
22+
@last_mouse_position = Vec2D.new(mouse_x, mouse_y)
23+
@start = java.lang.System.current_time_millis
24+
end
25+
26+
def playback_time_seconds
27+
(java.lang.System.current_time_millis - start) / 1000.0
28+
end
29+
30+
def render_time
31+
playback_time_seconds - previous_time
32+
end
33+
34+
def draw
35+
wrapper.set('iTime', playback_time_seconds)
36+
@previous_time = playback_time_seconds
37+
shader(wrapper)
38+
# Draw the output of the shader onto a rectangle that covers the whole viewport.
39+
rect(0, 0, width, height)
40+
end
41+
end
42+
43+
Sigmoids.new

0 commit comments

Comments
 (0)