ruby-processing 2.4.2 → 2.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +5 -0
- data/CONTRIBUTING.md +2 -0
- data/README.md +5 -5
- data/lib/ruby-processing/runners/base.rb +2 -0
- data/lib/ruby-processing/runners/watch.rb +3 -4
- data/lib/ruby-processing/version.rb +1 -1
- data/library/vecmath/lib/arcball.rb +64 -0
- data/library/vecmath/lib/quaternion.rb +62 -0
- data/library/vecmath/lib/vec.rb +216 -0
- data/library/vecmath/vecmath.rb +37 -323
- data/samples/Rakefile +19 -0
- data/samples/contributed/Rakefile +30 -0
- data/samples/contributed/bezier_playground.rb +14 -6
- data/samples/contributed/drawolver.rb +17 -38
- data/samples/contributed/full_screen.rb +2 -2
- data/samples/contributed/quadraticvertex.rb +10 -2
- data/samples/processing_app/library/vecmath/Rakefile +30 -0
- data/samples/processing_app/library/vecmath/library/flock/flock.rb +4 -4
- data/samples/processing_app/library/vecmath/retained_menger.rb +96 -96
- data/samples/processing_app/topics/advanced_data/Rakefile +30 -0
- data/samples/processing_app/topics/cellular_automata/library/ca/ca.rb +3 -3
- data/samples/processing_app/topics/lsystems/Rakefile +30 -0
- data/samples/processing_app/topics/motion/Rakefile +30 -0
- data/samples/processing_app/topics/shaders/Rakefile +30 -0
- data/samples/processing_app/topics/shaders/data/FishEye.glsl +59 -0
- data/vendors/Rakefile +2 -2
- metadata +14 -4
- data/samples/processing_app/topics/shaders/dome_projection.rb +0 -143
@@ -1,10 +1,14 @@
|
|
1
1
|
# Drawolver: draw 2D & revolve 3D
|
2
2
|
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
3
|
+
# This example demonstrates the use of the `vecmath` library (a ruby-processing
|
4
|
+
# replacement for PVector). Also demonstrated is how to extend an instance of a
|
5
|
+
# here an instance of a core ruby class. In this case the ruby Array class,
|
6
|
+
# is extended to yield one_of_each pair of pts (see ExtendedArray module). This
|
7
|
+
# examples also includes a possibly rare use of the each_cons Enumerable method?
|
8
|
+
# For simpler illustrations of `vecmath` usage see the library examples.
|
9
|
+
# 2010-03-22 - fjenett (last revised by monkstone 2014-02-18)
|
10
|
+
|
11
|
+
load_library :vecmath
|
8
12
|
|
9
13
|
attr_reader :drawing_mode, :points, :rot_x, :rot_y, :vertices
|
10
14
|
|
@@ -24,7 +28,6 @@ module ExtendedArray
|
|
24
28
|
end
|
25
29
|
end
|
26
30
|
|
27
|
-
|
28
31
|
def setup
|
29
32
|
size 1024, 768, P3D
|
30
33
|
frame_rate 30
|
@@ -71,15 +74,15 @@ end
|
|
71
74
|
|
72
75
|
def mouse_pressed
|
73
76
|
reset_scene
|
74
|
-
points <<
|
77
|
+
points << Vec3D.new(mouse_x, mouse_y)
|
75
78
|
end
|
76
79
|
|
77
80
|
def mouse_dragged
|
78
|
-
points <<
|
81
|
+
points << Vec3D.new(mouse_x, mouse_y)
|
79
82
|
end
|
80
83
|
|
81
84
|
def mouse_released
|
82
|
-
points <<
|
85
|
+
points << Vec3D.new(mouse_x, mouse_y)
|
83
86
|
recalculate_shape
|
84
87
|
end
|
85
88
|
|
@@ -87,16 +90,16 @@ def recalculate_shape
|
|
87
90
|
@vertices = []
|
88
91
|
points.each_cons(2) do |ps, pe|
|
89
92
|
b = points.last - points.first
|
90
|
-
len = b.mag
|
91
|
-
b.normalize
|
93
|
+
# len = b.mag
|
94
|
+
b.normalize!
|
92
95
|
a = ps - points.first
|
93
96
|
dot = a.dot b
|
94
|
-
b
|
97
|
+
b *= dot
|
95
98
|
normal = points.first + b
|
96
99
|
c = ps - normal
|
97
|
-
nlen = c.mag
|
100
|
+
# nlen = c.mag
|
98
101
|
vertices << []
|
99
|
-
(0..
|
102
|
+
(0..TAU).step(PI/15) do |ang|
|
100
103
|
e = normal + c * cos(ang)
|
101
104
|
e.z = c.mag * sin(ang)
|
102
105
|
vertices.last << e
|
@@ -105,27 +108,3 @@ def recalculate_shape
|
|
105
108
|
@drawing_mode = false
|
106
109
|
end
|
107
110
|
|
108
|
-
# a wrapper around PVector that implements operators methods for +, -, *, /
|
109
|
-
#
|
110
|
-
class RPVector < Java::ProcessingCore::PVector
|
111
|
-
|
112
|
-
def + (vect)
|
113
|
-
RPVector.new self.x + vect.x, self.y + vect.y, self.z + vect.z
|
114
|
-
end
|
115
|
-
|
116
|
-
def - (vect)
|
117
|
-
RPVector.new self.x - vect.x, self.y - vect.y, self.z - vect.z
|
118
|
-
end
|
119
|
-
|
120
|
-
def * (scalar)
|
121
|
-
RPVector.new self.x * scalar, self.y * scalar, self.z * scalar
|
122
|
-
end
|
123
|
-
|
124
|
-
def / (scalar)
|
125
|
-
RPVector.new(self.x / scalar, self.y / scalar, self.z / scalar) unless scalar == 0
|
126
|
-
end
|
127
|
-
|
128
|
-
end
|
129
|
-
|
130
|
-
|
131
|
-
|
@@ -9,10 +9,11 @@
|
|
9
9
|
|
10
10
|
load_library :control_panel
|
11
11
|
|
12
|
-
attr_reader :debug, :save_one, :step_angle, :cr, :detail, :panel
|
12
|
+
attr_reader :debug, :save_one, :step_angle, :cr, :detail, :panel, :hide
|
13
13
|
|
14
14
|
def setup
|
15
15
|
size 450, 320
|
16
|
+
@hide = false
|
16
17
|
control_panel do |c|
|
17
18
|
c.title = "controller"
|
18
19
|
c.menu(:detail, ['4', '5', '6', '7', '8', '9', '10' ], '7')
|
@@ -27,7 +28,10 @@ def setup
|
|
27
28
|
end
|
28
29
|
|
29
30
|
def draw
|
30
|
-
|
31
|
+
if (!hide)
|
32
|
+
panel.set_visible true
|
33
|
+
@hide = true
|
34
|
+
end
|
31
35
|
background color('#BDF018')
|
32
36
|
translate width / 2, height / 2
|
33
37
|
@step_angle = TWO_PI / (detail.to_i - 1)
|
@@ -73,6 +77,10 @@ def draw
|
|
73
77
|
end
|
74
78
|
end
|
75
79
|
|
80
|
+
def mouse_pressed
|
81
|
+
@hide = false
|
82
|
+
end
|
83
|
+
|
76
84
|
def cos_x(n)
|
77
85
|
cos(step_angle * n) * 100
|
78
86
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# Simple demo Rakefile to autorun samples in current directory
|
2
|
+
# adjust path to rp5 executable, and or opts as required
|
3
|
+
|
4
|
+
SAMPLES_DIR="./"
|
5
|
+
|
6
|
+
desc 'run demo'
|
7
|
+
task :default => [:demo]
|
8
|
+
|
9
|
+
desc 'demo'
|
10
|
+
task :demo do
|
11
|
+
samples_list.shuffle.each{|sample| run_sample sample}
|
12
|
+
end
|
13
|
+
|
14
|
+
def samples_list
|
15
|
+
files = []
|
16
|
+
Dir.chdir(SAMPLES_DIR)
|
17
|
+
Dir.glob("*.rb").each do |file|
|
18
|
+
files << File.join(SAMPLES_DIR, file)
|
19
|
+
end
|
20
|
+
return files
|
21
|
+
end
|
22
|
+
|
23
|
+
def run_sample(sample_name)
|
24
|
+
puts "Running #{sample_name}...quit to run next sample"
|
25
|
+
open("|rp5 --nojruby run #{sample_name}", "r") do |io|
|
26
|
+
while l = io.gets
|
27
|
+
puts(l.chop)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -172,8 +172,8 @@ class Boid
|
|
172
172
|
sum = Vec2D.new
|
173
173
|
count = 0
|
174
174
|
boids.each do |other|
|
175
|
-
d = Vec2D.
|
176
|
-
if ((d > 0) && (d < neighbordist))
|
175
|
+
d = Vec2D.dist_squared(location, other.location)
|
176
|
+
if ((d > 0) && (d < neighbordist * neighbordist))
|
177
177
|
sum += other.velocity
|
178
178
|
count += 1
|
179
179
|
end
|
@@ -199,8 +199,8 @@ class Boid
|
|
199
199
|
sum = Vec2D.new # Start with empty vector to accumulate all locations
|
200
200
|
count = 0
|
201
201
|
boids.each do |other|
|
202
|
-
d = Vec2D.
|
203
|
-
if ((d > 0) && (d < neighbordist))
|
202
|
+
d = Vec2D.dist_squared(location, other.location)
|
203
|
+
if ((d > 0) && (d < neighbordist * neighbordist))
|
204
204
|
sum += other.location # Add location
|
205
205
|
count += 1
|
206
206
|
end
|
@@ -16,126 +16,126 @@ Z = 2
|
|
16
16
|
attr_reader :arcball, :menger
|
17
17
|
|
18
18
|
def setup
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
size(640, 480, P3D)
|
20
|
+
smooth(8)
|
21
|
+
camera
|
22
|
+
camera(width/2.0, height/2.0, (height/2.0) / tan(PI*30.0 / 180.0), 0, 0, 0, 0, 1, 0)
|
23
|
+
@arcball = ArcBall.new(0, 0, min(width - 20, height - 20) * 0.8)
|
24
|
+
@menger = create_shape(GROUP)
|
25
|
+
create_menger(0, 0, 0, height * 0.8)
|
26
26
|
end
|
27
27
|
|
28
28
|
def draw
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
29
|
+
background(20, 20, 200)
|
30
|
+
no_stroke
|
31
|
+
lights
|
32
|
+
update
|
33
|
+
define_lights
|
34
|
+
render
|
35
|
+
end
|
36
36
|
|
37
37
|
def render
|
38
38
|
menger.set_fill(color(224, 223, 219))
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
menger.set_ambient(50)
|
40
|
+
menger.set_specular(150)
|
41
|
+
shape(menger)
|
42
42
|
end
|
43
43
|
|
44
44
|
def create_menger(xx, yy, zz, sz)
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
45
|
+
u = sz / 3.0
|
46
|
+
if (sz < MIN_SIZE) # recursion limited by minimum cube size
|
47
|
+
no_stroke
|
48
|
+
menger.add_child(create_cube(xx, yy, zz, sz)) # create and add a cube
|
49
|
+
else
|
50
|
+
PTS.each do |i|
|
51
|
+
PTS.each do |j|
|
52
|
+
PTS.each do |k|
|
53
|
+
if ((i.abs + j.abs + k.abs) > 1)
|
54
|
+
create_menger(xx + (i * u), yy + (j * u), zz + (k * u), u)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
60
|
end
|
61
61
|
|
62
62
|
def create_cube(xx, yy, zz, sz)
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
end
|
63
|
+
dim = sz / 2.0
|
64
|
+
cube = create_shape
|
65
|
+
cube.begin_shape(QUADS)
|
66
|
+
# Front face
|
67
|
+
cube.fill(255)
|
68
|
+
cube.normal(0, 0, 1)
|
69
|
+
cube.vertex(-dim + xx, -dim + yy, -dim + zz)
|
70
|
+
cube.vertex(+dim + xx, -dim + yy, -dim + zz)
|
71
|
+
cube.vertex(+dim + xx, +dim + yy, -dim + zz)
|
72
|
+
cube.vertex(-dim + xx, +dim + yy, -dim + zz)
|
73
|
+
|
74
|
+
# Back face
|
75
|
+
|
76
|
+
cube.normal(0, 0, -1)
|
77
|
+
cube.vertex(-dim + xx, -dim + yy, +dim + zz)
|
78
|
+
cube.vertex(+dim + xx, -dim + yy, +dim + zz)
|
79
|
+
cube.vertex(+dim + xx, +dim + yy, +dim + zz)
|
80
|
+
cube.vertex(-dim + xx, +dim + yy, +dim + zz)
|
81
|
+
|
82
|
+
# Left face
|
83
|
+
|
84
|
+
cube.normal(1, 0, 0)
|
85
|
+
cube.vertex(-dim + xx, -dim + yy, -dim + zz)
|
86
|
+
cube.vertex(-dim + xx, -dim + yy, +dim + zz)
|
87
|
+
cube.vertex(-dim + xx, +dim + yy, +dim + zz)
|
88
|
+
cube.vertex(-dim + xx, +dim + yy, -dim + zz)
|
89
|
+
|
90
|
+
# Right face
|
91
|
+
|
92
|
+
cube.normal(-1, 0, 0)
|
93
|
+
cube.vertex(+dim + xx, -dim + yy, -dim + zz)
|
94
|
+
cube.vertex(+dim + xx, -dim + yy, +dim + zz)
|
95
|
+
cube.vertex(+dim + xx, +dim + yy, +dim + zz)
|
96
|
+
cube.vertex(+dim + xx, +dim + yy, -dim + zz)
|
97
|
+
|
98
|
+
# Top face
|
99
|
+
|
100
|
+
cube.normal(0, 1, 0)
|
101
|
+
cube.vertex(-dim + xx, -dim + yy, -dim + zz)
|
102
|
+
cube.vertex(+dim + xx, -dim + yy, -dim + zz)
|
103
|
+
cube.vertex(+dim + xx, -dim + yy, +dim + zz)
|
104
|
+
cube.vertex(-dim + xx, -dim + yy, +dim + zz)
|
105
|
+
|
106
|
+
# Bottom face
|
107
|
+
|
108
|
+
cube.normal(0, -1, 0)
|
109
|
+
cube.vertex(-dim + xx, +dim + yy, -dim + zz)
|
110
|
+
cube.vertex(+dim + xx, +dim + yy, -dim + zz)
|
111
|
+
cube.vertex(+dim + xx, +dim + yy, +dim + zz)
|
112
|
+
cube.vertex(-dim + xx, +dim + yy, +dim + zz)
|
113
|
+
cube.end_shape
|
114
|
+
return cube
|
115
|
+
end
|
116
116
|
|
117
117
|
def update
|
118
|
-
|
119
|
-
|
118
|
+
theta, x, y, z = arcball.update
|
119
|
+
rotate(theta, x, y, z)
|
120
120
|
end
|
121
121
|
|
122
122
|
def mouse_pressed
|
123
|
-
|
123
|
+
arcball.mouse_pressed(mouse_x, mouse_y)
|
124
124
|
end
|
125
125
|
|
126
126
|
def mouse_dragged
|
127
|
-
|
127
|
+
arcball.mouse_dragged(mouse_x, mouse_y)
|
128
128
|
end
|
129
129
|
|
130
130
|
def define_lights
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
131
|
+
ambient_light(50, 50, 50)
|
132
|
+
point_light(30, 30, 30, 200, 240, 0)
|
133
|
+
directional_light(50, 50, 50, 1, 0, 0)
|
134
|
+
spot_light(30, 30, 30, 0, 40, 200, 0, -0.5, -0.5, PI / 2, 2)
|
135
135
|
end
|
136
136
|
|
137
|
-
def key_pressed
|
138
|
-
|
137
|
+
def key_pressed
|
138
|
+
case(key)
|
139
139
|
when 'x'
|
140
140
|
arcball.select_axis(X)
|
141
141
|
when 'y'
|
@@ -146,5 +146,5 @@ def key_pressed
|
|
146
146
|
end
|
147
147
|
|
148
148
|
def key_released
|
149
|
-
|
149
|
+
arcball.select_axis(-1)
|
150
150
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# Simple demo Rakefile to autorun samples in current directory
|
2
|
+
# adjust path to rp5 executable, and or opts as required
|
3
|
+
|
4
|
+
SAMPLES_DIR="./"
|
5
|
+
|
6
|
+
desc 'run demo'
|
7
|
+
task :default => [:demo]
|
8
|
+
|
9
|
+
desc 'demo'
|
10
|
+
task :demo do
|
11
|
+
samples_list.shuffle.each{|sample| run_sample sample}
|
12
|
+
end
|
13
|
+
|
14
|
+
def samples_list
|
15
|
+
files = []
|
16
|
+
Dir.chdir(SAMPLES_DIR)
|
17
|
+
Dir.glob("*.rb").each do |file|
|
18
|
+
files << File.join(SAMPLES_DIR, file)
|
19
|
+
end
|
20
|
+
return files
|
21
|
+
end
|
22
|
+
|
23
|
+
def run_sample(sample_name)
|
24
|
+
puts "Running #{sample_name}...quit to run next sample"
|
25
|
+
open("|rp5 --nojruby run #{sample_name}", "r") do |io|
|
26
|
+
while l = io.gets
|
27
|
+
puts(l.chop)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|