ruby-processing 1.0.9 → 1.0.10.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. data/CHANGELOG +13 -1
  2. data/bin/rp5 +8 -2
  3. data/lib/core/core.jar +0 -0
  4. data/lib/core/jruby-complete.jar +0 -0
  5. data/lib/ruby-processing.rb +2 -2
  6. data/lib/ruby-processing/app.rb +108 -338
  7. data/lib/ruby-processing/config.rb +6 -0
  8. data/lib/ruby-processing/helper_methods.rb +120 -0
  9. data/lib/ruby-processing/library_loader.rb +140 -0
  10. data/lib/ruby-processing/runner.rb +34 -4
  11. data/lib/ruby-processing/runners/base.rb +10 -11
  12. data/lib/ruby-processing/runners/live.rb +1 -1
  13. data/lib/ruby-processing/runners/run.rb +1 -1
  14. data/lib/ruby-processing/runners/watch.rb +18 -76
  15. data/lib/templates/applet/index.html.erb +8 -9
  16. data/library/control_panel/control_panel.rb +1 -1
  17. data/library/dxf/library/dxf.jar +0 -0
  18. data/library/dxf/library/export.txt +1 -0
  19. data/library/javascript/library/export.txt +3 -1
  20. data/library/minim/library/export.txt +1 -0
  21. data/library/minim/library/jl1.0.jar +0 -0
  22. data/library/minim/library/jsminim.jar +0 -0
  23. data/library/minim/library/minim-spi.jar +0 -0
  24. data/library/minim/library/minim.jar +0 -0
  25. data/library/minim/library/mp3spi1.9.4.jar +0 -0
  26. data/library/minim/library/tritonus_aos.jar +0 -0
  27. data/library/minim/library/tritonus_share.jar +0 -0
  28. data/library/net/library/export.txt +1 -0
  29. data/library/net/library/net.jar +0 -0
  30. data/library/opengl/library/export.txt +7 -10
  31. data/library/opengl/library/gluegen-rt.jar +0 -0
  32. data/library/opengl/library/jogl.jar +0 -0
  33. data/library/opengl/library/{libgluegen-rt.so → linux32/libgluegen-rt.so} +0 -0
  34. data/library/opengl/library/{libjogl.so → linux32/libjogl.so} +0 -0
  35. data/library/opengl/library/{libjogl_awt.so → linux32/libjogl_awt.so} +0 -0
  36. data/library/opengl/library/{libjogl_cg.so → linux32/libjogl_cg.so} +0 -0
  37. data/library/opengl/library/linux64/libgluegen-rt.so +0 -0
  38. data/library/opengl/library/linux64/libjogl.so +0 -0
  39. data/library/opengl/library/linux64/libjogl_awt.so +0 -0
  40. data/library/opengl/library/linux64/libjogl_cg.so +0 -0
  41. data/library/opengl/library/{libgluegen-rt.jnilib → macosx/libgluegen-rt.jnilib} +0 -0
  42. data/library/opengl/library/{libjogl.jnilib → macosx/libjogl.jnilib} +0 -0
  43. data/library/opengl/library/{libjogl_awt.jnilib → macosx/libjogl_awt.jnilib} +0 -0
  44. data/library/opengl/library/{libjogl_cg.jnilib → macosx/libjogl_cg.jnilib} +0 -0
  45. data/library/opengl/library/opengl.jar +0 -0
  46. data/library/opengl/library/{gluegen-rt.dll → windows32/gluegen-rt.dll} +0 -0
  47. data/library/opengl/library/{jogl.dll → windows32/jogl.dll} +0 -0
  48. data/library/opengl/library/{jogl_awt.dll → windows32/jogl_awt.dll} +0 -0
  49. data/library/opengl/library/{jogl_cg.dll → windows32/jogl_cg.dll} +0 -0
  50. data/library/opengl/library/windows64/gluegen-rt.dll +0 -0
  51. data/library/opengl/library/windows64/jogl.dll +0 -0
  52. data/library/opengl/library/windows64/jogl_awt.dll +0 -0
  53. data/library/opengl/library/windows64/jogl_cg.dll +0 -0
  54. data/library/pdf/library/export.txt +1 -0
  55. data/library/pdf/library/itext.jar +0 -0
  56. data/library/pdf/library/pdf.jar +0 -0
  57. data/library/serial/library/RXTXcomm.jar +0 -0
  58. data/library/serial/library/export.txt +1 -3
  59. data/library/serial/library/linux32/librxtxSerial.so +0 -0
  60. data/library/serial/library/linux64/librxtxSerial.so +0 -0
  61. data/library/serial/library/macosx/librxtxSerial.jnilib +0 -0
  62. data/library/serial/library/serial.jar +0 -0
  63. data/library/serial/library/windows32/rxtxSerial.dll +0 -0
  64. data/library/serial/library/windows64/rxtxSerial.dll +0 -0
  65. data/library/video/library/export.txt +1 -0
  66. data/library/video/library/video.jar +0 -0
  67. data/samples/{animator.rb → contributed/animator.rb} +0 -0
  68. data/samples/{bezier_playground.rb → contributed/bezier_playground.rb} +0 -0
  69. data/samples/{circle_collision.rb → contributed/circle_collision.rb} +0 -0
  70. data/samples/contributed/drawolver.rb +182 -0
  71. data/samples/{empathy.rb → contributed/empathy.rb} +7 -7
  72. data/samples/{fern.rb → contributed/fern.rb} +0 -0
  73. data/samples/{flight_patterns.rb → contributed/flight_patterns.rb} +0 -0
  74. data/samples/{full_screen.rb → contributed/full_screen.rb} +0 -0
  75. data/samples/{getting_started.rb → contributed/getting_started.rb} +0 -0
  76. data/samples/{gravity.rb → contributed/gravity.rb} +0 -0
  77. data/samples/{jwishy.rb → contributed/jwishy.rb} +0 -0
  78. data/samples/{orbit.rb → contributed/orbit.rb} +0 -0
  79. data/samples/{pong.rb → contributed/pong.rb} +0 -0
  80. data/samples/{reflection.rb → contributed/reflection.rb} +0 -0
  81. data/samples/{simple_buffer.rb → contributed/simple_buffer.rb} +0 -0
  82. data/samples/{tree.rb → contributed/tree.rb} +0 -0
  83. data/samples/peasy_cam/library/hilbert/hilbert.rb +11 -10
  84. data/samples/processing_app/3D/camera/move_eye.rb +29 -0
  85. data/samples/processing_app/3D/form/brick_tower.rb +11 -11
  86. data/samples/processing_app/3D/form/cubic_grid.rb +51 -0
  87. data/samples/processing_app/3D/form/icosahedra/icosahedra.rb +76 -0
  88. data/samples/processing_app/3D/form/icosahedra/icosahedron.rb +116 -0
  89. data/samples/processing_app/3D/form/icosahedra/shape_3D.rb +25 -0
  90. data/samples/processing_app/3D/form/primitives.rb +42 -0
  91. data/samples/processing_app/3D/form/rgb_cube.rb +88 -0
  92. data/samples/processing_app/3D/form/shape_transform.rb +94 -0
  93. data/samples/processing_app/3D/form/toroid.rb +130 -0
  94. data/samples/processing_app/3D/form/vertices.rb +81 -0
  95. data/samples/processing_app/3D/image/data/eames.jpg +0 -0
  96. data/samples/processing_app/3D/image/data/ystone08.jpg +0 -0
  97. data/samples/processing_app/3D/image/explode.rb +56 -0
  98. data/samples/processing_app/3D/image/extrusion.rb +49 -0
  99. data/samples/processing_app/3D/image/zoom.rb +83 -0
  100. data/samples/processing_app/3D/lights/directional.rb +41 -0
  101. data/samples/processing_app/3D/lights/lights1.rb +39 -0
  102. data/samples/processing_app/3D/lights/lights2.rb +42 -0
  103. data/samples/processing_app/3D/lights/reflection.rb +38 -0
  104. data/samples/processing_app/3D/lights/spot.rb +39 -0
  105. data/samples/processing_app/3D/textures/data/berlin-1.jpg +0 -0
  106. data/samples/processing_app/3D/textures/texture1.rb +41 -0
  107. data/samples/processing_app/3D/textures/texture2.rb +38 -0
  108. data/samples/processing_app/3D/textures/texture3.rb +68 -0
  109. data/samples/processing_app/3D/textures/texture_cube.rb +106 -0
  110. data/samples/processing_app/3D/transform/bird.rb +61 -0
  111. data/samples/processing_app/3D/transform/birds/bird.rb +87 -0
  112. data/samples/processing_app/3D/transform/birds/birds.rb +48 -0
  113. data/samples/processing_app/3D/transform/cubes_in_cube/cube.rb +57 -0
  114. data/samples/processing_app/3D/transform/cubes_in_cube/cubes_in_cube.rb +102 -0
  115. data/samples/processing_app/3D/transform/push_pop_cubes.rb +152 -0
  116. data/samples/processing_app/3D/transform/rotate1.rb +43 -0
  117. data/samples/processing_app/3D/transform/rotate2.rb +45 -0
  118. data/samples/processing_app/3D/typography/data/Univers45.vlw +0 -0
  119. data/samples/processing_app/3D/typography/letter_k.rb +136 -0
  120. data/samples/processing_app/3D/typography/typing.rb +77 -0
  121. data/samples/processing_app/basics/form/triangle_strip.rb +19 -19
  122. data/samples/processing_app/basics/math/distance1.rb +59 -0
  123. data/samples/processing_app/basics/math/distance2.rb +38 -0
  124. data/samples/processing_app/basics/math/double_random.rb +38 -0
  125. data/samples/processing_app/basics/math/graphing_2_d_equation.rb +53 -0
  126. data/samples/processing_app/basics/math/increment_decrement.rb +59 -0
  127. data/samples/processing_app/basics/math/modulo.rb +43 -0
  128. data/samples/processing_app/basics/math/noise_1_d.rb +37 -0
  129. data/samples/processing_app/basics/math/noise_2_d.rb +47 -0
  130. data/samples/processing_app/basics/math/noise_3_d.rb +50 -0
  131. data/samples/processing_app/basics/math/noise_wave.rb +61 -0
  132. data/samples/processing_app/basics/math/operator_precedence.rb +70 -0
  133. data/samples/processing_app/basics/math/polar_to_cartesian.rb +44 -0
  134. data/samples/processing_app/basics/math/random.rb +35 -0
  135. data/samples/processing_app/basics/math/sine.rb +49 -0
  136. data/samples/processing_app/basics/math/sine_cosine.rb +60 -0
  137. data/samples/processing_app/basics/math/sine_wave.rb +62 -0
  138. data/samples/processing_app/basics/objects/composite_objects.rb +139 -0
  139. data/samples/processing_app/basics/objects/inheritance.rb +104 -0
  140. data/samples/processing_app/basics/objects/multiple_constructors.rb +66 -0
  141. data/samples/processing_app/basics/objects/objects.rb +72 -0
  142. data/samples/processing_app/basics/shape/data/bot1.svg +160 -0
  143. data/samples/processing_app/basics/shape/data/usa-wikipedia.svg +452 -0
  144. data/samples/processing_app/basics/shape/disable_style.rb +36 -0
  145. data/samples/processing_app/basics/shape/get_child.rb +43 -0
  146. data/samples/processing_app/basics/shape/load_display_shape.rb +33 -0
  147. data/samples/processing_app/basics/shape/scale_shape.rb +33 -0
  148. data/samples/processing_app/basics/structure/coordinates.rb +55 -0
  149. data/samples/processing_app/basics/structure/create_graphics.rb +39 -0
  150. data/samples/processing_app/basics/structure/functions.rb +41 -0
  151. data/samples/processing_app/basics/structure/loop.rb +39 -0
  152. data/samples/processing_app/basics/structure/noloop.rb +33 -0
  153. data/samples/processing_app/basics/structure/recursion1.rb +42 -0
  154. data/samples/processing_app/basics/structure/recursion2.rb +39 -0
  155. data/samples/processing_app/basics/structure/redraw.rb +36 -0
  156. data/samples/processing_app/basics/structure/setup_draw.rb +30 -0
  157. data/samples/processing_app/basics/structure/statements_comments.rb +32 -0
  158. data/samples/processing_app/basics/structure/width_height.rb +29 -0
  159. data/samples/processing_app/basics/transform/arm.rb +47 -0
  160. data/samples/processing_app/basics/transform/rotate.rb +43 -0
  161. data/samples/processing_app/basics/transform/scale.rb +45 -0
  162. data/samples/processing_app/basics/transform/translate.rb +41 -0
  163. data/samples/processing_app/basics/transform/triangle_flower.rb +69 -0
  164. data/samples/processing_app/basics/typography/data/CourierNew36.vlw +0 -0
  165. data/samples/processing_app/basics/typography/data/Ziggurat-HTF-Black-32.vlw +0 -0
  166. data/samples/processing_app/basics/typography/letters.rb +52 -0
  167. data/samples/processing_app/basics/typography/words.rb +37 -0
  168. data/samples/processing_app/basics/web/embedded_links.rb +58 -0
  169. data/samples/processing_app/basics/web/loading_images.rb +25 -0
  170. metadata +181 -86
  171. data/lib/patches/JRubyApplet.diff +0 -24
  172. data/lib/patches/PATCHES.txt +0 -3
  173. data/lib/patches/PApplet.diff +0 -27
  174. data/library/minim/license.txt +0 -339
  175. data/library/minim/version.txt +0 -1
  176. data/library/opengl/library/gluegen-rt-natives-linux-amd64.jar +0 -0
  177. data/library/opengl/library/gluegen-rt-natives-linux-i586.jar +0 -0
  178. data/library/opengl/library/gluegen-rt-natives-macosx-ppc.jar +0 -0
  179. data/library/opengl/library/gluegen-rt-natives-macosx-universal.jar +0 -0
  180. data/library/opengl/library/gluegen-rt-natives-windows-amd64.jar +0 -0
  181. data/library/opengl/library/gluegen-rt-natives-windows-i586.jar +0 -0
  182. data/library/opengl/library/gluegen-rt.jar.pack.gz +0 -0
  183. data/library/opengl/library/jogl-natives-linux-amd64.jar +0 -0
  184. data/library/opengl/library/jogl-natives-linux-i586.jar +0 -0
  185. data/library/opengl/library/jogl-natives-macosx-ppc.jar +0 -0
  186. data/library/opengl/library/jogl-natives-macosx-universal.jar +0 -0
  187. data/library/opengl/library/jogl-natives-windows-amd64.jar +0 -0
  188. data/library/opengl/library/jogl-natives-windows-i586.jar +0 -0
  189. data/library/opengl/library/jogl.jar.pack.gz +0 -0
  190. data/library/pdf/notes.txt +0 -8
  191. data/library/serial/library/librxtxSerial.jnilib +0 -0
  192. data/library/serial/library/librxtxSerial.so +0 -0
  193. data/library/serial/library/rxtxSerial.dll +0 -0
@@ -0,0 +1,106 @@
1
+ # TexturedCube
2
+ # by Dave Bollinger.
3
+ #
4
+ # Drag mouse to rotate cube. Demonstrates use of u/v coords in
5
+ # vertex ) and effect on texture(). The textures get distorted using
6
+ # the P3D renderer as you can see, but they look great using OPENGL.
7
+
8
+ class TextureCube < Processing::App
9
+
10
+ def setup
11
+
12
+ size 649, 360, P3D
13
+
14
+ @rotx = PI/4
15
+ @roty = PI/4
16
+
17
+ @tex = load_image "berlin-1.jpg"
18
+ texture_mode NORMALIZED
19
+ fill 255
20
+ stroke 44, 48, 32
21
+
22
+ end
23
+
24
+ def draw
25
+
26
+ background 0
27
+
28
+ no_stroke
29
+
30
+ translate width/2, height/2, -100
31
+
32
+ rotate_x @rotx
33
+ rotate_y @roty
34
+
35
+ scale 90
36
+
37
+ texture_cube
38
+
39
+ end
40
+
41
+ def texture_cube
42
+
43
+ # Given one texture and six faces, we can easily set up the uv coordinates
44
+ # such that four of the faces tile "perfectly" along either u or v, but the other
45
+ # two faces cannot be so aligned. This code tiles "along" u, "around" the X/Z faces
46
+ # and fudges the Y faces - the Y faces are arbitrarily aligned such that a
47
+ # rotation along the X axis will put the "top" of either texture at the "top"
48
+ # of the screen, but is not otherwised aligned with the X/Z faces. (This
49
+ # just affects what type of symmetry is required if you need seamless
50
+ # tiling all the way around the cube)
51
+
52
+ begin_shape QUADS
53
+
54
+ texture @tex
55
+
56
+ # +Z "front" face
57
+ vertex -1, -1, 1, 0, 0
58
+ vertex 1, -1, 1, 1, 0
59
+ vertex 1, 1, 1, 1, 1
60
+ vertex -1, 1, 1, 0, 1
61
+
62
+ # -Z "back" face
63
+ vertex 1, -1, -1, 0, 0
64
+ vertex -1, -1, -1, 1, 0
65
+ vertex -1, 1, -1, 1, 1
66
+ vertex 1, 1, -1, 0, 1
67
+
68
+ # +Y "bottom" face
69
+ vertex -1, 1, 1, 0, 0
70
+ vertex 1, 1, 1, 1, 0
71
+ vertex 1, 1, -1, 1, 1
72
+ vertex -1, 1, -1, 0, 1
73
+
74
+ # -Y "top" face
75
+ vertex -1, -1, -1, 0, 0
76
+ vertex 1, -1, -1, 1, 0
77
+ vertex 1, -1, 1, 1, 1
78
+ vertex -1, -1, 1, 0, 1
79
+
80
+ # +X "right" face
81
+ vertex 1, -1, 1, 0, 0
82
+ vertex 1, -1, -1, 1, 0
83
+ vertex 1, 1, -1, 1, 1
84
+ vertex 1, 1, 1, 0, 1
85
+
86
+ # -X "left" face
87
+ vertex -1, -1, -1, 0, 0
88
+ vertex -1, -1, 1, 1, 0
89
+ vertex -1, 1, 1, 1, 1
90
+ vertex -1, 1, -1, 0, 1
91
+
92
+ end_shape
93
+
94
+ end
95
+
96
+ def mouse_dragged
97
+
98
+ rate = 0.01
99
+ @rotx += ( pmouse_y - mouse_y ) * rate
100
+ @roty += ( mouse_x - pmouse_x ) * rate
101
+
102
+ end
103
+
104
+ end
105
+
106
+ TextureCube.new :title => "Texture Cube"
@@ -0,0 +1,61 @@
1
+ # Simple 3D Bird
2
+ # by Ira Greenberg.
3
+ #
4
+ # Using a box and 2 rects to simulate a flying bird.
5
+ # Trig functions handle the flapping and sinuous movement.
6
+
7
+ class Bird < Processing::App
8
+
9
+ def setup
10
+
11
+ size 640, 360, P3D
12
+
13
+ no_stroke
14
+
15
+ @ang, @ang2, @ang3, @ang4 = 0.0, 0.0, 0.0, 0.0
16
+ @flap_speed = 0.2
17
+
18
+ end
19
+
20
+ def draw
21
+
22
+ background 0
23
+ lights
24
+
25
+ px = sin( radians @ang3 ) * 170
26
+ py = cos( radians @ang3 ) * 300
27
+ pz = sin( radians @ang4 ) * 500
28
+
29
+ translate width/2 + px, height/2 + py, -700 + pz
30
+
31
+ rotate_x sin( radians @ang2 ) * 120
32
+ rotate_y sin( radians @ang2 ) * 50
33
+ rotate_z sin( radians @ang2 ) * 65
34
+
35
+ fill 153
36
+ box 20, 100, 20
37
+
38
+ fill 204
39
+ push_matrix
40
+ rotate_y sin( radians @ang ) * -20
41
+ rect -75, -50, 75, 100
42
+ pop_matrix
43
+
44
+ push_matrix
45
+ rotate_y sin( radians @ang ) * 20
46
+ rect 0, -50, 75, 100
47
+ pop_matrix
48
+
49
+ @ang += @flap_speed
50
+
51
+ @flap_speed *= -1 if @ang > PI || @ang < -PI
52
+
53
+ @ang2 += 0.01
54
+ @ang3 += 2.0
55
+ @ang4 += 0.75
56
+
57
+ end
58
+
59
+ end
60
+
61
+ Bird.new :title => "Bird"
@@ -0,0 +1,87 @@
1
+ class Bird
2
+
3
+ include Processing::Proxy # mixin Processing commands
4
+
5
+ attr_accessor :offset_x, :offset_y, :offset_z
6
+ attr_accessor :w, :h
7
+ attr_accessor :body_fill, :wing_fill
8
+ attr_accessor :ang, :ang2, :ang3, :ang4
9
+ attr_accessor :radius_x, :radius_y, :radius_z
10
+ attr_accessor :rot_x, :rot_y, :rot_z
11
+ attr_accessor :flap_speed
12
+ attr_accessor :rot_speed
13
+
14
+ def initialize ( offset_x, offset_y, offset_z, w, h )
15
+
16
+ defaults
17
+ @offset_x, @offset_y, @offset_z = offset_x, offset_y, offset_z
18
+ @w, @h = w, h
19
+ end
20
+
21
+ def defaults
22
+
23
+ @ang, @ang2, @ang3, @ang4 = 0.0, 0.0, 0.0, 0.0
24
+ @body_fill, @wing_fill = color(153), color(204)
25
+ @flap_speed = 0.4
26
+ @rot_speed = 0.1
27
+ @radius_x, @radius_y, @radius_z = 120.0, 200.0, 700.0
28
+ end
29
+
30
+ def set_flight ( radius_x, radius_y, radius_z, rot_x, rot_y, rot_z )
31
+
32
+ @radius_x, @radius_y, @radius_z = radius_x, radius_y, radius_z
33
+ @rot_x, @rot_y, @rot_z = rot_x, rot_y, rot_z
34
+ end
35
+
36
+ def set_wing_speed ( flap_speed )
37
+
38
+ @flap_speed = flap_speed
39
+ end
40
+
41
+ def set_rot_speed ( rot_speed )
42
+
43
+ @rot_speed = rot_speed
44
+ end
45
+
46
+ def fly
47
+
48
+ push_matrix
49
+
50
+ px = sin( radians @ang3 ) * @radius_x
51
+ py = cos( radians @ang3 ) * @radius_y
52
+ pz = sin( radians @ang4 ) * @radius_z
53
+
54
+ translate @offset_x + px,
55
+ @offset_y + py,
56
+ @offset_z + pz
57
+
58
+ rotate_x sin( radians @ang2 ) * @rot_x
59
+ rotate_y sin( radians @ang2 ) * @rot_y
60
+ rotate_z sin( radians @ang2 ) * @rot_z
61
+
62
+ fill @body_fill
63
+ box @w/5, @h, @w/5
64
+
65
+ fill @wing_fill
66
+
67
+ push_matrix
68
+ rotate_y sin( radians @ang ) * 20
69
+ rect 0, -@h/2, @w, @h
70
+ pop_matrix
71
+
72
+ push_matrix
73
+ rotate_y sin( radians @ang ) * -20
74
+ rect -@w, -@h/2, @w, @h
75
+ pop_matrix
76
+
77
+ @ang += @flap_speed
78
+ @flap_speed *= -1 if @ang > PI || @ang < -PI
79
+
80
+ @ang2 += @rot_speed
81
+ @ang3 += 1.25
82
+ @ang4 += 0.55
83
+
84
+ pop_matrix
85
+ end
86
+
87
+ end
@@ -0,0 +1,48 @@
1
+ # Crazy Flocking 3D Birds
2
+ # by Ira Greenberg.
3
+ #
4
+ # Simulates a flock of birds using a Bird class and nested
5
+ # pushMatrix() / popMatrix() functions.
6
+ # Trigonometry functions handle the flapping and sinuous movement.
7
+
8
+ require 'bird' # class Bird
9
+
10
+ class Birds < Processing::App
11
+
12
+ def setup
13
+
14
+ size 640, 360, P3D
15
+ no_stroke
16
+ lights
17
+
18
+ @bird_count = 200
19
+ @birds = []
20
+
21
+ 0.upto( @bird_count ) { |i|
22
+
23
+ bird = Bird.new random(-300,300), random(-300,300), random(-500,-2500), random(5,30), random(5,30)
24
+
25
+ bird.set_flight random( 20, 340 ), random( 30, 350 ), random( 1000, 4800 ),
26
+ random( -160, 160 ), random( -55, 55 ), random( -20, 20 )
27
+
28
+ bird.set_wing_speed random( 0.1, 3.75 )
29
+ bird.set_rot_speed random( 0.025, 0.15 )
30
+
31
+ @birds.push bird
32
+ }
33
+
34
+ end
35
+
36
+ def draw
37
+
38
+ background 0
39
+
40
+ translate width/2, height/2, -700
41
+
42
+ @birds.each do |b| b.fly end
43
+
44
+ end
45
+
46
+ end
47
+
48
+ Birds.new :title => "Birds"
@@ -0,0 +1,57 @@
1
+ require 'ruby-processing/app' # require Processing::Proxi
2
+
3
+ class Cube
4
+
5
+ include Processing::Proxy # mixin Processing::Proxi
6
+
7
+ attr_accessor :vertices
8
+ attr_accessor :w, :h, :d
9
+ attr_accessor :position, :speed, :rotation # PVector
10
+
11
+ def initialize ( w, h, d )
12
+
13
+ @w, @h, @d = w, h, d
14
+
15
+ w2 = @w/2
16
+ h2 = @h/2
17
+ d2 = @d/2
18
+
19
+ tfl = PVector.new -w2, h2, d2 # four points making the top quad:
20
+ tfr = PVector.new w2, h2, d2 # "tfl" is "top front left", etc
21
+ tbr = PVector.new w2, h2,-d2
22
+ tbl = PVector.new -w2, h2,-d2
23
+
24
+ bfl = PVector.new -w2,-h2, d2 # bottom quad points
25
+ bfr = PVector.new w2,-h2, d2
26
+ bbr = PVector.new w2,-h2,-d2
27
+ bbl = PVector.new -w2,-h2,-d2
28
+
29
+ @vertices = [
30
+ [tfl, tfr, tbr, tbl], # top
31
+ [tfl, tfr, bfr, bfl], # front
32
+ [tfl, tbl, bbl, bfl], # left
33
+ [tbl, tbr, bbr, bbl], # back
34
+ [tbr, tfr, bfr, bbr], # right
35
+ [bfl, bfr, bbr, bbl]
36
+ ]
37
+ end
38
+
39
+ def draw ( side_colors = nil )
40
+
41
+ @vertices.each_with_index { |quad, i| # each face
42
+
43
+ begin_shape QUADS
44
+
45
+ fill side_colors[i] if side_colors && i < side_colors.length
46
+
47
+ quad.each { |pvec|
48
+
49
+ vertex pvec.x, pvec.y, pvec.z
50
+ }
51
+
52
+ end_shape
53
+
54
+ }
55
+ end
56
+
57
+ end
@@ -0,0 +1,102 @@
1
+ # Cubes Contained Within a Cube
2
+ # by Ira Greenberg.
3
+ #
4
+ # Collision detection against all outer cube's surfaces.
5
+ # Uses the PVector and Cube classes.
6
+
7
+ # fjenett, 2010-03-12: did some cleanups and rubyfication here
8
+
9
+ require 'cube'
10
+
11
+ class CubesInCube < Processing::App
12
+
13
+ def setup
14
+
15
+ size 640, 360, P3D
16
+
17
+ lights
18
+
19
+ @cube_count = 20
20
+ @cubes = []
21
+
22
+ 0.upto( @cube_count ) { |i|
23
+
24
+ cube_size = random( 5, 15 )
25
+
26
+ c = Cube.new cube_size, cube_size, cube_size
27
+
28
+ c.position = PVector.new 0.0, 0.0, 0.0
29
+ c.speed = PVector.new random(-1,1), random(-1,1), random(-1,1)
30
+ c.rotation = PVector.new random(40,100), random(40,100), random(40,100)
31
+
32
+ @cubes.push c
33
+ }
34
+
35
+ @cube_colors = [
36
+ color( 0 ), color( 51 ), color( 102 ), color( 153 ), color( 204 ), color( 255 )
37
+ ]
38
+ @cube_colors.reverse
39
+
40
+ @stage_size = 300
41
+ @stage = Cube.new @stage_size, @stage_size, @stage_size
42
+
43
+ end
44
+
45
+ def draw
46
+
47
+ background 50
48
+
49
+ translate width/2, height/2, -130
50
+
51
+ rotate_x frame_count * 0.001
52
+ rotate_y frame_count * 0.002
53
+ rotate_z frame_count * 0.001
54
+
55
+ no_fill
56
+ stroke 255
57
+
58
+ @stage.draw
59
+
60
+ @cubes.each_with_index { |c, i|
61
+
62
+ # draw cube
63
+ push_matrix
64
+
65
+ translate c.position.x, c.position.y, c.position.z
66
+
67
+ fcpi = frame_count * PI
68
+ rotate_x fcpi / c.rotation.x
69
+ rotate_y fcpi / c.rotation.y
70
+ rotate_x fcpi / c.rotation.z
71
+
72
+ no_stroke
73
+
74
+ c.draw @cube_colors
75
+
76
+ pop_matrix
77
+
78
+ # move it
79
+ c.position.add c.speed
80
+
81
+ # draw lines
82
+ if i > 0
83
+
84
+ stroke 0
85
+ c2 = @cubes[i-1]
86
+ line c.position.x, c.position.y, c.position.z,
87
+ c2.position.x, c2.position.y, c2.position.z
88
+
89
+ end
90
+
91
+ # collision
92
+ s2 = @stage_size / 2
93
+ c.speed.x *= -1 if ( c.position.x / s2 ).abs > 1 # note that in Ruby abs(-12) is -12.abs
94
+ c.speed.y *= -1 if ( c.position.y / s2 ).abs > 1
95
+ c.speed.z *= -1 if ( c.position.z / s2 ).abs > 1
96
+ }
97
+
98
+ end
99
+
100
+ end
101
+
102
+ CubesInCube.new :title => "Cubes In Cube"