ruby-processing 1.0.5 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +8 -0
- data/lib/ruby-processing.rb +1 -1
- data/lib/ruby-processing/app.rb +85 -20
- data/lib/ruby-processing/exporters/base_exporter.rb +1 -1
- data/lib/ruby-processing/runners/base.rb +1 -1
- data/lib/ruby-processing/runners/watch.rb +1 -1
- data/lib/templates/applet/images/built_with.jpg +0 -0
- data/lib/templates/applet/images/ruby.jpg +0 -0
- data/lib/templates/applet/index.html.erb +7 -3
- data/lib/templates/application/Contents/Resources/sketch.icns +0 -0
- data/library/control_panel/control_panel.rb +18 -13
- data/samples/circle_collision.rb +72 -85
- data/samples/getting_started.rb +1 -0
- data/samples/jwishy.rb +8 -7
- data/samples/orbit.rb +27 -32
- data/samples/processing_app/3D/camera/ortho_vs_perspective.rb +22 -30
- data/samples/processing_app/3D/camera/perspective.rb +21 -29
- data/samples/processing_app/3D/form/brick_tower.rb +46 -54
- data/samples/processing_app/3D/typography/kinetic_type.rb +36 -35
- data/samples/processing_app/topics/simulate/multiple_particle_systems.rb +74 -73
- data/samples/reflection.rb +13 -22
- metadata +2 -2
data/samples/getting_started.rb
CHANGED
data/samples/jwishy.rb
CHANGED
@@ -11,8 +11,6 @@
|
|
11
11
|
|
12
12
|
# -- omygawshkenas
|
13
13
|
|
14
|
-
require 'ruby-processing'
|
15
|
-
|
16
14
|
class Sketch < Processing::App
|
17
15
|
load_libraries :control_panel, :net
|
18
16
|
|
@@ -20,18 +18,20 @@ class Sketch < Processing::App
|
|
20
18
|
|
21
19
|
def setup
|
22
20
|
control_panel do |c|
|
23
|
-
c.slider :bluish, 0.0..1.0
|
24
|
-
c.slider :alpha, 0.0..1.0
|
21
|
+
c.slider :bluish, 0.0..1.0, 0.5
|
22
|
+
c.slider :alpha, 0.0..1.0, 0.5
|
25
23
|
c.checkbox :go_big
|
26
24
|
c.button :reset
|
25
|
+
c.menu :shape, ['oval', 'square']
|
27
26
|
end
|
28
27
|
|
28
|
+
@shape = 'oval'
|
29
|
+
@alpha, @bluish = 0.5, 0.5
|
29
30
|
@x_wiggle, @y_wiggle = 10.0, 0
|
30
31
|
@magnitude = 8.15
|
31
|
-
@bluish = 0.9
|
32
32
|
@background = [0.06, 0.03, 0.18]
|
33
|
-
@alpha = 1.0
|
34
33
|
color_mode RGB, 1
|
34
|
+
ellipse_mode CORNER
|
35
35
|
smooth
|
36
36
|
end
|
37
37
|
|
@@ -70,7 +70,8 @@ class Sketch < Processing::App
|
|
70
70
|
y += log10(vert)*mag + sin(vert) * 2
|
71
71
|
fill(sin(@y_wiggle + c), rand * 0.2, rand * blu, 0.5)
|
72
72
|
s = 42 + cos(vert) * 17
|
73
|
-
|
73
|
+
args = [x-s/2, y-s/2, s, s]
|
74
|
+
@shape == 'oval' ? oval(*args) : rect(*args)
|
74
75
|
vert += rand * 0.25
|
75
76
|
horiz += rand * 0.25
|
76
77
|
c += 0.1
|
data/samples/orbit.rb
CHANGED
@@ -3,43 +3,38 @@
|
|
3
3
|
# This sketch demonstrates how to use the frame rate as orbital state,
|
4
4
|
# as well as how to use system fonts in Ruby-Processing.
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
@font = create_font('Helvetica', 40)
|
14
|
-
end
|
6
|
+
def setup
|
7
|
+
size 450, 450
|
8
|
+
frame_rate 30
|
9
|
+
smooth
|
10
|
+
fill 0
|
11
|
+
@font = create_font('Helvetica', 40)
|
12
|
+
end
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
def draw
|
15
|
+
background 255
|
16
|
+
translate 225, 225
|
19
17
|
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
text_font @font
|
19
|
+
ellipse 0, 0, 10, 10
|
20
|
+
text 'sun', 10, 0
|
23
21
|
|
24
|
-
|
25
|
-
|
22
|
+
3.times do |i|
|
23
|
+
push_matrix
|
26
24
|
|
27
|
-
|
28
|
-
|
25
|
+
rotate frame_count / -180.0 * PI + i * PI / -1.5
|
26
|
+
line 0, 0, 120, 0
|
29
27
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
translate 120, 0
|
29
|
+
ellipse 0, 0, 10, 10
|
30
|
+
text_font @font, 22
|
31
|
+
text 'planet', 10, 0
|
34
32
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
33
|
+
rotate frame_count / -30.0 * PI
|
34
|
+
line 0, 0, 30, 0
|
35
|
+
text_font @font, 15
|
36
|
+
text 'moon', 32, 0
|
39
37
|
|
40
|
-
|
41
|
-
end
|
38
|
+
pop_matrix
|
42
39
|
end
|
43
|
-
end
|
44
|
-
|
45
|
-
Orbit.new :width => 450, :height => 450, :title => 'Orbit'
|
40
|
+
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
1
|
# Click to see the difference between orthographic projection
|
4
2
|
# and perspective projection as applied to a simple box.
|
5
3
|
# The ortho function sets an orthographic projection and
|
@@ -11,36 +9,30 @@ require 'ruby-processing'
|
|
11
9
|
# minimum and maximum y values, and near and far are the minimum
|
12
10
|
# and maximum z values.
|
13
11
|
|
14
|
-
|
12
|
+
def setup
|
13
|
+
size 640, 360, P3D
|
14
|
+
no_stroke
|
15
|
+
fill 204
|
16
|
+
end
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
fill 204
|
20
|
-
end
|
21
|
-
|
22
|
-
def draw
|
23
|
-
background 0
|
24
|
-
lights
|
25
|
-
|
26
|
-
mouse_pressed? ? show_perspective : show_orthographic
|
27
|
-
|
28
|
-
translate width/2, height/2, 0
|
29
|
-
rotate_x -PI/6
|
30
|
-
rotate_y PI/3
|
31
|
-
box 160
|
32
|
-
end
|
18
|
+
def draw
|
19
|
+
background 0
|
20
|
+
lights
|
33
21
|
|
34
|
-
|
35
|
-
fov = PI/3.0
|
36
|
-
camera_z = (height/2.0) / tan(PI * fov / 360.0)
|
37
|
-
perspective fov, width.to_f/height.to_f, camera_z/2.0, camera_z*2.0
|
38
|
-
end
|
39
|
-
|
40
|
-
def show_orthographic
|
41
|
-
ortho -width/2, width/2, -height/2, height/2, -10, 10
|
42
|
-
end
|
22
|
+
mouse_pressed? ? show_perspective : show_orthographic
|
43
23
|
|
24
|
+
translate width/2, height/2, 0
|
25
|
+
rotate_x -PI/6
|
26
|
+
rotate_y PI/3
|
27
|
+
box 160
|
28
|
+
end
|
29
|
+
|
30
|
+
def show_perspective
|
31
|
+
fov = PI/3.0
|
32
|
+
camera_z = (height/2.0) / tan(PI * fov / 360.0)
|
33
|
+
perspective fov, width.to_f/height.to_f, camera_z/2.0, camera_z*2.0
|
44
34
|
end
|
45
35
|
|
46
|
-
|
36
|
+
def show_orthographic
|
37
|
+
ortho -width/2, width/2, -height/2, height/2, -10, 10
|
38
|
+
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
1
|
# Move the mouse left and right to change the field of view (fov).
|
4
2
|
# Click to modify the aspect ratio. The perspective method
|
5
3
|
# sets a perspective projection applying foreshortening, making
|
@@ -12,33 +10,27 @@ require 'ruby-processing'
|
|
12
10
|
# perspective and the version with four parameters allows the programmer
|
13
11
|
# to set the area precisely.
|
14
12
|
|
15
|
-
|
13
|
+
def setup
|
14
|
+
size 640, 360, P3D
|
15
|
+
no_stroke
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
def draw
|
19
|
+
lights
|
20
|
+
background 204
|
21
|
+
camera_y = height/2.0
|
22
|
+
fov = mouse_x/width.to_f * PI/2.0
|
23
|
+
camera_z = camera_y / tan(fov / 2.0)
|
24
|
+
aspect = width.to_f / height.to_f
|
21
25
|
|
22
|
-
|
23
|
-
lights
|
24
|
-
background 204
|
25
|
-
camera_y = height/2.0
|
26
|
-
fov = mouse_x/width.to_f * PI/2.0
|
27
|
-
camera_z = camera_y / tan(fov / 2.0)
|
28
|
-
aspect = width.to_f / height.to_f
|
29
|
-
|
30
|
-
aspect /= 2.0 if mouse_pressed?
|
31
|
-
|
32
|
-
perspective(fov, aspect, camera_z/10.0, camera_z*10.0)
|
33
|
-
|
34
|
-
translate width/2.0+30, height/2.0, 0
|
35
|
-
rotate_x -PI/6
|
36
|
-
rotate_y PI/3 + mouse_y/height.to_f * PI
|
37
|
-
box 45
|
38
|
-
translate 0, 0, -50
|
39
|
-
box 30
|
40
|
-
end
|
26
|
+
aspect /= 2.0 if mouse_pressed?
|
41
27
|
|
42
|
-
|
43
|
-
|
44
|
-
|
28
|
+
perspective(fov, aspect, camera_z/10.0, camera_z*10.0)
|
29
|
+
|
30
|
+
translate width/2.0+30, height/2.0, 0
|
31
|
+
rotate_x -PI/6
|
32
|
+
rotate_y PI/3 + mouse_y/height.to_f * PI
|
33
|
+
box 45
|
34
|
+
translate 0, 0, -50
|
35
|
+
box 30
|
36
|
+
end
|
@@ -1,55 +1,50 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
1
|
# Original by Ira Greenberg
|
4
2
|
|
5
3
|
# 3D castle tower constructed out of individual bricks.
|
6
4
|
# Uses the PVecor and Cube classes.
|
7
5
|
|
8
|
-
|
6
|
+
def setup
|
7
|
+
@bricks_per_layer = 16
|
8
|
+
@brick_layers = 18
|
9
|
+
@brick_width, @brick_height, @brick_depth = 60, 25, 25
|
10
|
+
@radius = 175.0
|
11
|
+
@angle = 0
|
12
|
+
size 640, 360, P3D
|
13
|
+
@brick = Cubeish.new(@brick_width, @brick_height, @brick_depth)
|
14
|
+
end
|
9
15
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
@temp_x = sin(radians(@angle)) * @radius
|
43
|
-
push_matrix
|
44
|
-
translate @temp_x, @temp_y, @temp_z
|
45
|
-
rotate_y(radians(@angle))
|
46
|
-
top_layer = @layer_num == @brick_layers - 1
|
47
|
-
even_brick = @brick_num % 2 == 0
|
48
|
-
@brick.create unless top_layer # main tower
|
49
|
-
@brick.create if top_layer && even_brick # add crenelation
|
50
|
-
pop_matrix
|
51
|
-
@angle += 360.0 / @bricks_per_layer
|
52
|
-
end
|
16
|
+
def draw
|
17
|
+
background 0
|
18
|
+
@temp_x, @temp_y, @temp_z = 0, 0, 0
|
19
|
+
fill 182, 62, 29
|
20
|
+
no_stroke
|
21
|
+
lights
|
22
|
+
translate(width/2.0, height*1.2, -380) # move viewpoint into position
|
23
|
+
rotate_x(radians(-45)) # tip tower to see inside
|
24
|
+
rotate_y(frame_count * PI/600) # slowly rotate tower
|
25
|
+
@brick_layers.times {|i| draw_layer(i) }
|
26
|
+
end
|
27
|
+
|
28
|
+
def draw_layer(layer_num)
|
29
|
+
@layer_num = layer_num
|
30
|
+
@temp_y -= @brick_height # increment rows
|
31
|
+
@angle = 360.0 / @bricks_per_layer * @layer_num / 2.0 # alternate brick seams
|
32
|
+
@bricks_per_layer.times {|i| draw_bricks(i) }
|
33
|
+
end
|
34
|
+
|
35
|
+
def draw_bricks(brick_num)
|
36
|
+
@brick_num = brick_num
|
37
|
+
@temp_z = cos(radians(@angle)) * @radius
|
38
|
+
@temp_x = sin(radians(@angle)) * @radius
|
39
|
+
push_matrix
|
40
|
+
translate @temp_x, @temp_y, @temp_z
|
41
|
+
rotate_y(radians(@angle))
|
42
|
+
top_layer = @layer_num == @brick_layers - 1
|
43
|
+
even_brick = @brick_num % 2 == 0
|
44
|
+
@brick.create unless top_layer # main tower
|
45
|
+
@brick.create if top_layer && even_brick # add crenelation
|
46
|
+
pop_matrix
|
47
|
+
@angle += 360.0 / @bricks_per_layer
|
53
48
|
end
|
54
49
|
|
55
50
|
|
@@ -75,20 +70,17 @@ class Cubeish
|
|
75
70
|
SIDES.each do |side, signs|
|
76
71
|
@vertices[side] = signs.map do |s|
|
77
72
|
s = s.split('').map {|el| SIGNS[el] }
|
78
|
-
|
73
|
+
App::PVector.new(s[0]*@w/2, s[1]*@h/2, s[2]*@d/2)
|
79
74
|
end
|
80
75
|
end
|
81
76
|
end
|
82
77
|
|
83
78
|
def create
|
84
79
|
@vertices.each do |name, vectors|
|
85
|
-
|
86
|
-
vectors.each {|v|
|
87
|
-
|
80
|
+
begin_shape App::QUADS
|
81
|
+
vectors.each {|v| vertex(v.x, v.y, v.z) }
|
82
|
+
end_shape
|
88
83
|
end
|
89
84
|
end
|
90
85
|
|
91
|
-
end
|
92
|
-
|
93
|
-
|
94
|
-
BrickTower.new :title => "Brick Tower", :width => 640, :height => 360
|
86
|
+
end
|
@@ -1,8 +1,7 @@
|
|
1
1
|
# From the Processing Examples
|
2
2
|
# by Zach Lieberman
|
3
3
|
# Ruby version thanks to Nick Sieger
|
4
|
-
|
5
|
-
require 'ruby-processing'
|
4
|
+
# Demonstrates method-proxying for inner classes.
|
6
5
|
|
7
6
|
class KineticType < Processing::App
|
8
7
|
load_library :opengl
|
@@ -36,44 +35,46 @@ class KineticType < Processing::App
|
|
36
35
|
pop_matrix
|
37
36
|
end
|
38
37
|
end
|
39
|
-
end
|
40
|
-
|
41
|
-
class Line
|
42
|
-
include Math
|
43
|
-
attr_accessor :string, :xpos, :ypos, :letters
|
44
|
-
|
45
|
-
def initialize(string, x, y)
|
46
|
-
@string, @xpos, @ypos = string, x, y
|
47
|
-
spacing = 0.0
|
48
|
-
@letters = @string.split('').map do |c|
|
49
|
-
spacing += $app.text_width(c)
|
50
|
-
Letter.new(c, spacing, 0.0)
|
51
|
-
end
|
52
|
-
end
|
53
38
|
|
54
|
-
def compute_curve(line_num)
|
55
|
-
base = $app.millis / 10000.0 * PI * 2
|
56
|
-
sin((line_num + 1.0) * base) * sin((8.0 - line_num) * base)
|
57
|
-
end
|
58
39
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
40
|
+
class Line
|
41
|
+
include Math
|
42
|
+
attr_accessor :string, :xpos, :ypos, :letters
|
43
|
+
|
44
|
+
def initialize(string, x, y)
|
45
|
+
@string, @xpos, @ypos = string, x, y
|
46
|
+
spacing = 0.0
|
47
|
+
@letters = @string.split('').map do |c|
|
48
|
+
spacing += text_width(c)
|
49
|
+
Letter.new(c, spacing, 0.0)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def compute_curve(line_num)
|
54
|
+
base = millis / 10000.0 * PI * 2
|
55
|
+
sin((line_num + 1.0) * base) * sin((8.0 - line_num) * base)
|
56
|
+
end
|
57
|
+
|
58
|
+
def draw(line_num)
|
59
|
+
curve = compute_curve(line_num)
|
60
|
+
@letters.each_with_index do |letter, i|
|
61
|
+
translate(text_width(@letters[i-1].char)*75, 0.0, 0.0) if i > 0
|
62
|
+
rotate_y(curve * 0.035)
|
63
|
+
push_matrix
|
64
|
+
scale(75.0, 75.0, 75.0)
|
65
|
+
text(letter.char, 0.0, 0.0)
|
66
|
+
pop_matrix
|
67
|
+
end
|
68
68
|
end
|
69
69
|
end
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
70
|
+
|
71
|
+
class Letter
|
72
|
+
attr_accessor :char, :x, :y
|
73
|
+
def initialize(c, x, y)
|
74
|
+
@char, @x, @y = c, x, y
|
75
|
+
end
|
76
76
|
end
|
77
|
+
|
77
78
|
end
|
78
79
|
|
79
80
|
KineticType.new :width => 200, :height => 200, :title => "Kinetic Type"
|