ruby-processing 2.4.3 → 2.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/CHANGELOG +5 -0
- data/README.md +4 -2
- data/lib/ruby-processing/exporters/application_exporter.rb +1 -0
- data/lib/ruby-processing/version.rb +1 -1
- data/library/boids/boids.rb +14 -13
- data/library/vecmath/lib/vec.rb +20 -4
- data/samples/contributed/circle_collision.rb +92 -149
- data/samples/contributed/drawolver.rb +13 -27
- data/samples/contributed/elegant_ball.rb +158 -0
- data/samples/contributed/fern.rb +16 -3
- data/samples/contributed/flight_patterns.rb +16 -4
- data/samples/external_library/java_processing/{pbox2d → box2d_processing}/bumpy_surface_noise.rb +4 -9
- data/samples/external_library/java_processing/{pbox2d → box2d_processing}/data/java_args.txt +0 -0
- data/samples/external_library/java_processing/{pbox2d → box2d_processing}/library/custom_shape/custom_shape.rb +1 -1
- data/samples/external_library/java_processing/{pbox2d → box2d_processing}/library/particle_system/particle_system.rb +7 -10
- data/samples/external_library/java_processing/{pbox2d → box2d_processing}/library/surface/surface.rb +2 -2
- data/samples/external_library/java_processing/{pbox2d → box2d_processing}/liquidy.rb +7 -7
- data/samples/external_library/java_processing/{pbox2d → box2d_processing}/polygons.rb +4 -9
- data/samples/external_library/java_processing/custom/README.md +15 -0
- data/samples/external_library/java_processing/custom/Rakefile +28 -0
- data/samples/external_library/java_processing/custom/landscape.rb +58 -0
- data/samples/external_library/java_processing/custom/src/nn/Connection.java +47 -0
- data/samples/external_library/java_processing/custom/src/nn/HiddenNeuron.java +20 -0
- data/samples/external_library/java_processing/custom/src/nn/InputNeuron.java +23 -0
- data/samples/external_library/java_processing/custom/src/nn/Network.java +136 -0
- data/samples/external_library/java_processing/custom/src/nn/Neuron.java +79 -0
- data/samples/external_library/java_processing/custom/src/nn/OutputNeuron.java +7 -0
- data/samples/external_library/java_processing/custom/xor.rb +88 -0
- data/samples/external_library/ruby_gem/README +1 -1
- data/samples/external_library/ruby_gem/data/data.json +8 -0
- data/samples/external_library/ruby_gem/draw_test.rb +171 -0
- data/samples/processing_app/basics/form/icosahedra.rb +39 -0
- data/samples/processing_app/basics/form/library/icosahedron/icosahedron.rb +60 -0
- data/samples/processing_app/basics/form/toroid.rb +78 -92
- data/samples/processing_app/basics/transform/birds.rb +6 -12
- data/samples/processing_app/basics/transform/cubes_in_cube.rb +25 -22
- data/samples/processing_app/basics/transform/library/cube/cube.rb +16 -16
- data/samples/processing_app/basics/transform/rotate_push_pop.rb +1 -1
- data/samples/processing_app/demos/graphics/bezier_patch.rb +18 -31
- data/samples/processing_app/demos/graphics/trefoil.rb +15 -15
- data/samples/processing_app/library/vecmath/acceleration_with_vectors.rb +3 -3
- data/samples/processing_app/library/vecmath/hilbert_fractal.rb +2 -2
- data/samples/processing_app/library/vecmath/library/flock/flock.rb +18 -21
- data/samples/processing_app/library/vecmath/library/hilbert/hilbert.rb +11 -8
- data/samples/processing_app/library/vecmath/library/wiggler/wiggler.rb +7 -15
- data/samples/processing_app/library/vecmath/seeking_neural.rb +172 -0
- data/samples/processing_app/topics/animation/animated_sprite.rb +5 -8
- data/samples/processing_app/topics/animation/sequential.rb +2 -3
- data/samples/processing_app/topics/create_shapes/library/particle/particle_system.rb +7 -7
- data/samples/processing_app/topics/create_shapes/particle_system_pshape.rb +2 -2
- data/samples/processing_app/topics/create_shapes/wiggle_pshape.rb +2 -1
- data/samples/processing_app/topics/lsystems/koch.rb +1 -1
- data/samples/processing_app/topics/lsystems/library/koch/koch_fractal.rb +24 -23
- data/samples/processing_app/topics/motion/circle_collision.rb +117 -160
- data/samples/processing_app/topics/motion/library/cube/cube.rb +1 -1
- data/samples/processing_app/topics/motion/morph.rb +1 -1
- data/samples/processing_app/topics/motion/reflection1.rb +17 -16
- data/samples/processing_app/topics/shaders/conway.rb +2 -2
- data/samples/processing_app/topics/shaders/data/conway.glsl +10 -10
- data/samples/processing_app/topics/shaders/glsl_heightmap_noise.rb +9 -8
- data/samples/processing_app/topics/shaders/landscape.rb +1 -1
- data/samples/processing_app/topics/simulate/flocking.rb +1 -1
- data/samples/processing_app/topics/simulate/library/flock/flock.rb +62 -57
- data/samples/processing_app/topics/simulate/multiple_particle_systems.rb +8 -28
- data/samples/processing_app/topics/simulate/simple_particle_system.rb +9 -7
- data/samples/processing_app/topics/simulate/smoke_particle_system.rb +12 -11
- data/vendors/Rakefile +2 -2
- metadata +26 -21
- data/samples/contributed/pong.rb +0 -177
- data/samples/contributed/simple_buffer.rb +0 -44
- data/samples/external_library/java_processing/pbox2d/contact_test.rb +0 -23
- data/samples/processing_app/basics/form/icosahedra/icosahedra.rb +0 -72
- data/samples/processing_app/basics/form/icosahedra/icosahedron.rb +0 -116
- data/samples/processing_app/basics/form/icosahedra/shape_3D.rb +0 -25
@@ -1,184 +1,141 @@
|
|
1
1
|
# Based on http://processing.org/learning/topics/circlecollision.html
|
2
|
-
# by Joe Holt
|
3
2
|
|
3
|
+
load_library :vecmath
|
4
4
|
|
5
5
|
|
6
|
-
# This inner class demonstrates the use of Ruby-Processing's emulation of
|
7
|
-
# Java inner classes. The Balls are able to call Processing::App methods.
|
8
6
|
class Ball
|
9
|
-
attr_accessor :
|
10
|
-
|
11
|
-
|
7
|
+
attr_accessor :position, :r, :m, :velocity
|
8
|
+
|
9
|
+
def initialize(x = 0.0, y = 0.0, r = 0.0)
|
10
|
+
@position = Vec2D.new(x, y)
|
11
|
+
@r = r
|
12
12
|
@m = r * 0.1
|
13
|
-
@
|
14
|
-
end
|
13
|
+
@velocity = Vec2D.new(rand(-3.0 .. 3), rand(-3.0 .. 3))
|
14
|
+
end
|
15
15
|
|
16
|
-
def
|
17
|
-
@
|
18
|
-
@y += @vec.y
|
16
|
+
def update
|
17
|
+
@position += velocity
|
19
18
|
end
|
20
19
|
|
21
|
-
def
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
def check_boundary width, height
|
21
|
+
if (position.x > width - r)
|
22
|
+
position.x = width - r
|
23
|
+
velocity.x *= -1
|
24
|
+
elsif (position.x < r)
|
25
|
+
position.x = r
|
26
|
+
velocity.x *= -1
|
27
|
+
elsif (position.y > height - r)
|
28
|
+
position.y = height - r
|
29
|
+
velocity.y *= -1
|
30
|
+
elsif (position.y < r)
|
31
|
+
position.y = r
|
32
|
+
velocity.y *= -1
|
33
|
+
end
|
25
34
|
end
|
26
35
|
|
27
|
-
def
|
28
|
-
|
29
|
-
|
36
|
+
def check_collision balls
|
37
|
+
balls.each do |other_ball|
|
38
|
+
if !(other_ball.equal?(self))
|
39
|
+
# get distances between the balls components
|
40
|
+
difference = other_ball.position - position
|
41
|
+
|
42
|
+
# calculate magnitude of the vector separating the balls
|
43
|
+
|
44
|
+
dist_mag_squared = difference.mag_squared
|
45
|
+
|
46
|
+
if dist_mag_squared < (r + other_ball.r) * (r + other_ball.r)
|
47
|
+
# get angle of difference
|
48
|
+
theta = difference.heading
|
49
|
+
# precalculate trig values
|
50
|
+
sine = sin(theta)
|
51
|
+
cosine = cos(theta)
|
52
|
+
|
53
|
+
# ball_array will hold rotated ball positions. You just
|
54
|
+
# need to worry about ball_array[1] position
|
55
|
+
ball_array = [Ball.new, Ball.new]
|
56
|
+
# other_ball's position is relative to ball's
|
57
|
+
# so you can use the vector between them (difference) as the
|
58
|
+
# reference point in the rotation expressions.
|
59
|
+
# ball_array[0].x and ball_array[0].y will initialize
|
60
|
+
# automatically to 0.0, which is what you want
|
61
|
+
# since other_ball will rotate around ball
|
62
|
+
ball_array[1].position.x = cosine * difference.x + sine * difference.y
|
63
|
+
ball_array[1].position.y = cosine * difference.y - sine * difference.x
|
64
|
+
|
65
|
+
# rotate Temporary velocities
|
66
|
+
velocity_array = [Vec2D.new, Vec2D.new]
|
67
|
+
velocity_array[0].x = cosine * velocity.x + sine * velocity.y
|
68
|
+
velocity_array[0].y = cosine * velocity.y - sine * velocity.x
|
69
|
+
velocity_array[1].x = cosine * other_ball.velocity.x + sine * other_ball.velocity.y
|
70
|
+
velocity_array[1].y = cosine * other_ball.velocity.y - sine * other_ball.velocity.x
|
71
|
+
|
72
|
+
# Now that velocities are rotated, you can use 1D
|
73
|
+
# conservation of momentum equations to calculate
|
74
|
+
# the final velocity along the x-axis.
|
75
|
+
final_velocities = [Vec2D.new, Vec2D.new]
|
76
|
+
# final rotated velocity for ball
|
77
|
+
final_velocities[0].x = ((m - other_ball.m) * velocity_array[0].x + 2 * other_ball.m * velocity_array[1].x) / (m + other_ball.m)
|
78
|
+
final_velocities[0].y = velocity_array[0].y
|
79
|
+
# final rotated velocity for ball
|
80
|
+
final_velocities[1].x = ((other_ball.m - m) * velocity_array[1].x + 2 * m * velocity_array[0].x) / (m + other_ball.m)
|
81
|
+
final_velocities[1].y = velocity_array[1].y
|
82
|
+
|
83
|
+
# hack to avoid clumping
|
84
|
+
ball_array[0].position.x += final_velocities[0].x
|
85
|
+
ball_array[1].position.x += final_velocities[1].x
|
86
|
+
|
87
|
+
# Rotate ball positions and velocities back
|
88
|
+
# Reverse signs in trig expressions to rotate
|
89
|
+
# in the opposite direction
|
90
|
+
# rotate balls
|
91
|
+
final_positions = [Vec2D.new, Vec2D.new]
|
92
|
+
final_positions[0].x = cosine * ball_array[0].position.x - sine * ball_array[0].position.y
|
93
|
+
final_positions[0].y = cosine * ball_array[0].position.y + sine * ball_array[0].position.x
|
94
|
+
final_positions[1].x = cosine * ball_array[1].position.x - sine * ball_array[1].position.y
|
95
|
+
final_positions[1].y = cosine * ball_array[1].position.y + sine * ball_array[1].position.x
|
96
|
+
|
97
|
+
# update balls to screen position
|
98
|
+
other_ball.position = position + final_positions[1]
|
99
|
+
@position += final_positions[0]
|
100
|
+
|
101
|
+
# update velocities
|
102
|
+
velocity.x = cosine * final_velocities[0].x - sine * final_velocities[0].y
|
103
|
+
velocity.y = cosine * final_velocities[0].y + sine * final_velocities[0].x
|
104
|
+
other_ball.velocity.x = cosine * final_velocities[1].x - sine * final_velocities[1].y
|
105
|
+
other_ball.velocity.y = cosine * final_velocities[1].y + sine * final_velocities[1].x
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
30
109
|
end
|
31
|
-
end
|
32
|
-
|
33
|
-
|
34
|
-
def setup
|
35
|
-
size 400, 400
|
36
|
-
no_stroke
|
37
|
-
frame_rate 30
|
38
|
-
rect_mode RADIUS
|
39
|
-
@balls = []
|
40
|
-
5.times { @balls << Ball.new(10, PVector.new(2.15, -1.35), *empty_space(15)) }
|
41
|
-
2.times { @balls << Ball.new(40, PVector.new(-1.65, 0.42), *empty_space(45)) }
|
42
|
-
@frame_time = nil
|
43
|
-
@frame_count = 0
|
44
|
-
end
|
45
|
-
|
46
|
-
|
47
|
-
def draw
|
48
|
-
t = Time.now
|
49
|
-
fps = 1.0 / (t - @frame_time) if @frame_time
|
50
|
-
@frame_time = t
|
51
|
-
@frame_count += 1
|
52
110
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
fill 51
|
58
|
-
@balls.each { |ball| ball.erase }
|
111
|
+
def display
|
112
|
+
no_stroke
|
113
|
+
fill(204)
|
114
|
+
ellipse(position.x, position.y, r * 2, r * 2)
|
59
115
|
end
|
60
116
|
|
61
|
-
# move the balls
|
62
|
-
fill 240
|
63
|
-
@balls.each do |ball|
|
64
|
-
ball.move
|
65
|
-
ball.draw
|
66
|
-
check_boundary_collision ball
|
67
|
-
end
|
68
|
-
check_object_collisions
|
69
117
|
end
|
70
118
|
|
119
|
+
attr_reader :balls
|
71
120
|
|
72
|
-
def
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
def empty_space?(x, y, r)
|
83
|
-
@balls.each do |ball|
|
84
|
-
vx = x - ball.x
|
85
|
-
vy = y - ball.y
|
86
|
-
mag = sqrt(vx * vx + vy * vy)
|
87
|
-
return false if mag < r + ball.r
|
88
|
-
end
|
89
|
-
return true
|
90
|
-
end
|
91
|
-
|
92
|
-
|
93
|
-
def check_object_collisions
|
94
|
-
|
95
|
-
(0...(@balls.length)).each do |ia|
|
96
|
-
((ia+1)...(@balls.length)).each do |ib|
|
97
|
-
|
98
|
-
ba = @balls[ia]
|
99
|
-
bb = @balls[ib]
|
100
|
-
|
101
|
-
# get distances between the balls components
|
102
|
-
bVect = PVector.new
|
103
|
-
bVect.x = bb.x - ba.x
|
104
|
-
bVect.y = bb.y - ba.y
|
105
|
-
|
106
|
-
# calculate magnitude of the vector separating the balls
|
107
|
-
bVectMag = bVect.mag
|
108
|
-
next if bVectMag >= ba.r + bb.r
|
109
|
-
# get angle of bVect
|
110
|
-
theta = atan2(bVect.y, bVect.x)
|
111
|
-
# precalculate trig values
|
112
|
-
sine = sin(theta)
|
113
|
-
cosine = cos(theta)
|
114
|
-
|
115
|
-
# bTemp will hold rotated ball positions. You just
|
116
|
-
# need to worry about bTemp[1] position
|
117
|
-
bTemp = [Ball.new, Ball.new]
|
118
|
-
# bb's position is relative to ba's
|
119
|
-
# so you can use the vector between them (bVect) as the
|
120
|
-
# reference point in the rotation expressions.
|
121
|
-
# bTemp[0].x and bTemp[0].y will initialize
|
122
|
-
# automatically to 0.0, which is what you want
|
123
|
-
# since bb will rotate around ba
|
124
|
-
bTemp[1].x = cosine * bVect.x + sine * bVect.y
|
125
|
-
bTemp[1].y = cosine * bVect.y - sine * bVect.x
|
126
|
-
|
127
|
-
# rotate Temporary velocities
|
128
|
-
vTemp = [PVector.new, PVector.new]
|
129
|
-
vTemp[0].x = cosine * ba.vec.x + sine * ba.vec.y
|
130
|
-
vTemp[0].y = cosine * ba.vec.y - sine * ba.vec.x
|
131
|
-
vTemp[1].x = cosine * bb.vec.x + sine * bb.vec.y
|
132
|
-
vTemp[1].y = cosine * bb.vec.y - sine * bb.vec.x
|
133
|
-
|
134
|
-
# Now that velocities are rotated, you can use 1D
|
135
|
-
# conservation of momentum equations to calculate
|
136
|
-
# the final velocity along the x-axis.
|
137
|
-
vFinal = [PVector.new, PVector.new]
|
138
|
-
# final rotated velocity for ba
|
139
|
-
vFinal[0].x = ((ba.m - bb.m) * vTemp[0].x + 2 * bb.m * vTemp[1].x) / (ba.m + bb.m)
|
140
|
-
vFinal[0].y = vTemp[0].y
|
141
|
-
# final rotated velocity for ba
|
142
|
-
vFinal[1].x = ((bb.m - ba.m) * vTemp[1].x + 2 * ba.m * vTemp[0].x) / (ba.m + bb.m)
|
143
|
-
vFinal[1].y = vTemp[1].y
|
144
|
-
|
145
|
-
# hack to avoid clumping
|
146
|
-
bTemp[0].x += vFinal[0].x
|
147
|
-
bTemp[1].x += vFinal[1].x
|
148
|
-
|
149
|
-
# Rotate ball positions and velocities back
|
150
|
-
# Reverse signs in trig expressions to rotate
|
151
|
-
# in the opposite direction
|
152
|
-
# rotate balls
|
153
|
-
bFinal = [Ball.new, Ball.new]
|
154
|
-
bFinal[0].x = cosine * bTemp[0].x - sine * bTemp[0].y
|
155
|
-
bFinal[0].y = cosine * bTemp[0].y + sine * bTemp[0].x
|
156
|
-
bFinal[1].x = cosine * bTemp[1].x - sine * bTemp[1].y
|
157
|
-
bFinal[1].y = cosine * bTemp[1].y + sine * bTemp[1].x
|
158
|
-
|
159
|
-
# update balls to screen position
|
160
|
-
bb.x = ba.x + bFinal[1].x
|
161
|
-
bb.y = ba.y + bFinal[1].y
|
162
|
-
ba.x = ba.x + bFinal[0].x
|
163
|
-
ba.y = ba.y + bFinal[0].y
|
164
|
-
|
165
|
-
# update velocities
|
166
|
-
ba.vec.x = cosine * vFinal[0].x - sine * vFinal[0].y
|
167
|
-
ba.vec.y = cosine * vFinal[0].y + sine * vFinal[0].x
|
168
|
-
bb.vec.x = cosine * vFinal[1].x - sine * vFinal[1].y
|
169
|
-
bb.vec.y = cosine * vFinal[1].y + sine * vFinal[1].x
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
121
|
+
def setup
|
122
|
+
size 640, 360
|
123
|
+
@balls = [
|
124
|
+
Ball.new(100, 400, 20),
|
125
|
+
Ball.new(100, 100, 20),
|
126
|
+
Ball.new(200, 100, 20),
|
127
|
+
Ball.new(700, 400, 60)
|
128
|
+
]
|
173
129
|
end
|
174
130
|
|
175
131
|
|
176
|
-
def
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
132
|
+
def draw
|
133
|
+
background(51)
|
134
|
+
balls.each do |b|
|
135
|
+
b.update
|
136
|
+
b.display
|
137
|
+
b.check_boundary width, height
|
138
|
+
b.check_collision(balls)
|
182
139
|
end
|
183
140
|
end
|
184
141
|
|
@@ -111,7 +111,7 @@ Boundary = Struct.new(:lower, :upper) do
|
|
111
111
|
end
|
112
112
|
|
113
113
|
# Leaner meaner substitute for vanilla processings
|
114
|
-
# PVector class, provides only functionality we need
|
114
|
+
# PVector class, provides only the functionality we need
|
115
115
|
#
|
116
116
|
Vect = Struct.new(:x, :y, :z) do
|
117
117
|
|
@@ -6,6 +6,7 @@
|
|
6
6
|
# reflection vector, N is the normal, and L is the incident
|
7
7
|
# vector.
|
8
8
|
#
|
9
|
+
load_library :vecmath
|
9
10
|
|
10
11
|
attr_reader :base1, :base2, :base_length, :coords, :position, :radius
|
11
12
|
attr_reader :direction, :speed, :velocity, :incidence
|
@@ -15,14 +16,14 @@ def setup
|
|
15
16
|
@radius = 6
|
16
17
|
@speed = 3.5
|
17
18
|
fill(128)
|
18
|
-
@base1 =
|
19
|
-
@base2 =
|
19
|
+
@base1 = Vec2D.new(0, height - 150)
|
20
|
+
@base2 = Vec2D.new(width, height)
|
20
21
|
@coords = create_ground
|
21
22
|
# start ellipse at middle top of screen
|
22
|
-
@position =
|
23
|
+
@position = Vec2D.new(width/2, 0)
|
23
24
|
# set initial random direction
|
24
|
-
@direction =
|
25
|
-
@velocity =
|
25
|
+
@direction = Vec2D.new(rand(-1.0 .. 1), rand(-1.0 .. 1))
|
26
|
+
@velocity = Vec2D.new
|
26
27
|
end
|
27
28
|
|
28
29
|
def draw
|
@@ -36,34 +37,34 @@ def draw
|
|
36
37
|
quad(base1.x, base1.y, base2.x, base2.y, base2.x, height, 0, height)
|
37
38
|
|
38
39
|
# calculate base top normal
|
39
|
-
base_delta =
|
40
|
-
base_delta.normalize
|
41
|
-
normal =
|
40
|
+
base_delta = base2 - base1
|
41
|
+
base_delta.normalize!
|
42
|
+
normal = Vec2D.new(-base_delta.y, base_delta.x)
|
42
43
|
# draw ellipse
|
43
44
|
no_stroke
|
44
45
|
fill(255)
|
45
46
|
ellipse(position.x, position.y, radius * 2, radius * 2)
|
46
47
|
|
47
48
|
# set ellipse velocity
|
48
|
-
@velocity.
|
49
|
-
@velocity
|
49
|
+
@velocity.x, @velocity.y = direction.x, direction.y
|
50
|
+
@velocity *= speed
|
50
51
|
|
51
52
|
# move ellipse
|
52
|
-
@position
|
53
|
+
@position += velocity
|
53
54
|
|
54
55
|
# normalized incidence vector
|
55
|
-
@incidence =
|
56
|
+
@incidence = direction * -1
|
56
57
|
|
57
58
|
# detect and handle collision
|
58
59
|
coords.each do |coord|
|
59
60
|
# check distance between ellipse and base top coordinates
|
60
|
-
if (
|
61
|
+
if (Vec2D.dist_squared(position, coord) < radius * radius)
|
61
62
|
|
62
63
|
# calculate dot product of incident vector and base top normal
|
63
64
|
dot = incidence.dot(normal)
|
64
65
|
|
65
66
|
# assign reflection vector to direction vector
|
66
|
-
direction.
|
67
|
+
direction.x, direction.y = 2*normal.x*dot - incidence.x, 2*normal.y*dot - incidence.y
|
67
68
|
# draw base top normal at collision point
|
68
69
|
stroke(255, 128, 0)
|
69
70
|
line(position.x, position.y, position.x - normal.x*100, position.y - normal.y*100)
|
@@ -94,11 +95,11 @@ end
|
|
94
95
|
|
95
96
|
def create_ground
|
96
97
|
# calculate length of base top
|
97
|
-
@base_length =
|
98
|
+
@base_length = Vec2D.dist(base1, base2)
|
98
99
|
# fill base top coordinate array
|
99
100
|
coords = []
|
100
101
|
(0 ... base_length.ceil).each do |i|
|
101
|
-
coords <<
|
102
|
+
coords << Vec2D.new(
|
102
103
|
base1.x + ((base2.x - base1.x) / base_length) * i,
|
103
104
|
base1.y + ((base2.y - base1.y) / base_length) * i)
|
104
105
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# GLSL version of Conway's game of life, ported from GLSL sandbox:
|
2
2
|
# http://glsl.heroku.com/e/207.3
|
3
|
-
# Exemplifies the use of the
|
4
|
-
# access to the previous frame.
|
3
|
+
# Exemplifies the use of the ppixels uniform in the shader, that gives
|
4
|
+
# access to the pixels of the previous frame.
|
5
5
|
attr_accessor :pg, :conway
|
6
6
|
|
7
7
|
def setup
|
@@ -9,7 +9,7 @@ precision highp float;
|
|
9
9
|
uniform float time;
|
10
10
|
uniform vec2 mouse;
|
11
11
|
uniform vec2 resolution;
|
12
|
-
uniform sampler2D
|
12
|
+
uniform sampler2D ppixels;
|
13
13
|
|
14
14
|
vec4 live = vec4(0.5,1.0,0.7,1.);
|
15
15
|
vec4 dead = vec4(0.,0.,0.,1.);
|
@@ -28,15 +28,15 @@ void main( void ) {
|
|
28
28
|
}
|
29
29
|
} else {
|
30
30
|
float sum = 0.;
|
31
|
-
sum += texture2D(
|
32
|
-
sum += texture2D(
|
33
|
-
sum += texture2D(
|
34
|
-
sum += texture2D(
|
35
|
-
sum += texture2D(
|
36
|
-
sum += texture2D(
|
37
|
-
sum += texture2D(
|
38
|
-
sum += texture2D(
|
39
|
-
vec4 me = texture2D(
|
31
|
+
sum += texture2D(ppixels, position + pixel * vec2(-1., -1.)).g;
|
32
|
+
sum += texture2D(ppixels, position + pixel * vec2(-1., 0.)).g;
|
33
|
+
sum += texture2D(ppixels, position + pixel * vec2(-1., 1.)).g;
|
34
|
+
sum += texture2D(ppixels, position + pixel * vec2(1., -1.)).g;
|
35
|
+
sum += texture2D(ppixels, position + pixel * vec2(1., 0.)).g;
|
36
|
+
sum += texture2D(ppixels, position + pixel * vec2(1., 1.)).g;
|
37
|
+
sum += texture2D(ppixels, position + pixel * vec2(0., -1.)).g;
|
38
|
+
sum += texture2D(ppixels, position + pixel * vec2(0., 1.)).g;
|
39
|
+
vec4 me = texture2D(ppixels, position);
|
40
40
|
|
41
41
|
if (me.g <= 0.1) {
|
42
42
|
if ((sum >= 2.9) && (sum <= 3.1)) {
|
@@ -11,6 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# Photographs by Folkert Gorter (@folkertgorter / http://superfamous.com/) made available under a CC Attribution 3.0 license.
|
13
13
|
#
|
14
|
+
load_library :vecmath
|
14
15
|
|
15
16
|
DIM = 300 # the grid dimensions of the heightmap
|
16
17
|
attr_reader :blur_factor # the blur for the displacement map (to make it smoother)
|
@@ -78,16 +79,16 @@ def create_plane(xsegs, ysegs)
|
|
78
79
|
v = y / ysegs.to_f
|
79
80
|
|
80
81
|
# generate positions for the vertices of each cell (-0.5 to center the shape around the origin)
|
81
|
-
positions <<
|
82
|
-
positions <<
|
83
|
-
positions <<
|
84
|
-
positions <<
|
82
|
+
positions << Vec3D.new(u - 0.5, v - 0.5, 0)
|
83
|
+
positions << Vec3D.new(u + usegsize - 0.5, v - 0.5, 0)
|
84
|
+
positions << Vec3D.new(u + usegsize - 0.5, v + vsegsize - 0.5, 0)
|
85
|
+
positions << Vec3D.new(u - 0.5, v + vsegsize - 0.5, 0)
|
85
86
|
|
86
87
|
# generate texture coordinates for the vertices of each cell
|
87
|
-
tex_coords <<
|
88
|
-
tex_coords <<
|
89
|
-
tex_coords <<
|
90
|
-
tex_coords <<
|
88
|
+
tex_coords << Vec2D.new(u, v)
|
89
|
+
tex_coords << Vec2D.new(u + usegsize, v)
|
90
|
+
tex_coords << Vec2D.new(u + usegsize, v + vsegsize)
|
91
|
+
tex_coords << Vec2D.new(u, v + vsegsize)
|
91
92
|
end
|
92
93
|
end
|
93
94
|
|