ruby-processing 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (220) hide show
  1. data/CHANGELOG +137 -0
  2. data/LICENSE +37 -0
  3. data/README +61 -0
  4. data/bin/rp5 +4 -0
  5. data/lib/core/core.jar +0 -0
  6. data/lib/core/jruby-complete.jar +0 -0
  7. data/lib/ruby-processing.rb +27 -0
  8. data/lib/ruby-processing/app.rb +358 -0
  9. data/lib/ruby-processing/exporters/applet_exporter.rb +75 -0
  10. data/lib/ruby-processing/exporters/application_exporter.rb +87 -0
  11. data/lib/ruby-processing/exporters/base_exporter.rb +133 -0
  12. data/lib/ruby-processing/exporters/creator.rb +46 -0
  13. data/lib/ruby-processing/helpers/string.rb +27 -0
  14. data/lib/ruby-processing/runner.rb +143 -0
  15. data/lib/ruby-processing/runners/base.rb +5 -0
  16. data/lib/ruby-processing/runners/live.rb +11 -0
  17. data/lib/ruby-processing/runners/run.rb +5 -0
  18. data/lib/ruby-processing/runners/watch.rb +42 -0
  19. data/lib/templates/applet/images/built_with.jpg +0 -0
  20. data/lib/templates/applet/images/ruby.jpg +0 -0
  21. data/lib/templates/applet/images/top.png +0 -0
  22. data/lib/templates/applet/index.html.erb +111 -0
  23. data/lib/templates/applet/library/library.txt +1 -0
  24. data/lib/templates/application/Contents/Info.plist.erb +58 -0
  25. data/lib/templates/application/Contents/MacOS/JavaApplicationStub +0 -0
  26. data/lib/templates/application/Contents/PkgInfo +1 -0
  27. data/lib/templates/application/Contents/Resources/sketch.icns +0 -0
  28. data/lib/templates/application/lib/MANIFEST.MF +3 -0
  29. data/lib/templates/application/lib/args.txt.erb +3 -0
  30. data/lib/templates/application/lib/library/library.txt +1 -0
  31. data/lib/templates/application/run.erb +4 -0
  32. data/lib/templates/application/run.exe +0 -0
  33. data/lib/templates/create/blank_sketch.rb.erb +15 -0
  34. data/library/boids/boids.rb +222 -0
  35. data/library/control_panel/control_panel.rb +149 -0
  36. data/library/dxf/bin/processing/dxf/RawDXF.class +0 -0
  37. data/library/dxf/dxfviewer.jar +0 -0
  38. data/library/dxf/library/dxf.jar +0 -0
  39. data/library/javascript/library/export.txt +6 -0
  40. data/library/javascript/library/javascript.jar +0 -0
  41. data/library/minim/library/jl1.0.jar +0 -0
  42. data/library/minim/library/jsminim.jar +0 -0
  43. data/library/minim/library/minim-spi.jar +0 -0
  44. data/library/minim/library/minim.jar +0 -0
  45. data/library/minim/library/mp3spi1.9.4.jar +0 -0
  46. data/library/minim/library/tritonus_aos.jar +0 -0
  47. data/library/minim/library/tritonus_share.jar +0 -0
  48. data/library/minim/license.txt +339 -0
  49. data/library/minim/version.txt +1 -0
  50. data/library/net/bin/processing/net/Client.class +0 -0
  51. data/library/net/bin/processing/net/Server.class +0 -0
  52. data/library/net/library/net.jar +0 -0
  53. data/library/opengl/bin/processing/opengl/PGraphicsOpenGL$ImageCache.class +0 -0
  54. data/library/opengl/bin/processing/opengl/PGraphicsOpenGL$TessCallback.class +0 -0
  55. data/library/opengl/bin/processing/opengl/PGraphicsOpenGL.class +0 -0
  56. data/library/opengl/library/export.txt +13 -0
  57. data/library/opengl/library/gluegen-rt-natives-linux-amd64.jar +0 -0
  58. data/library/opengl/library/gluegen-rt-natives-linux-i586.jar +0 -0
  59. data/library/opengl/library/gluegen-rt-natives-macosx-ppc.jar +0 -0
  60. data/library/opengl/library/gluegen-rt-natives-macosx-universal.jar +0 -0
  61. data/library/opengl/library/gluegen-rt-natives-windows-amd64.jar +0 -0
  62. data/library/opengl/library/gluegen-rt-natives-windows-i586.jar +0 -0
  63. data/library/opengl/library/gluegen-rt.dll +0 -0
  64. data/library/opengl/library/gluegen-rt.jar +0 -0
  65. data/library/opengl/library/gluegen-rt.jar.pack.gz +0 -0
  66. data/library/opengl/library/jogl-natives-linux-amd64.jar +0 -0
  67. data/library/opengl/library/jogl-natives-linux-i586.jar +0 -0
  68. data/library/opengl/library/jogl-natives-macosx-ppc.jar +0 -0
  69. data/library/opengl/library/jogl-natives-macosx-universal.jar +0 -0
  70. data/library/opengl/library/jogl-natives-windows-amd64.jar +0 -0
  71. data/library/opengl/library/jogl-natives-windows-i586.jar +0 -0
  72. data/library/opengl/library/jogl.dll +0 -0
  73. data/library/opengl/library/jogl.jar +0 -0
  74. data/library/opengl/library/jogl.jar.pack.gz +0 -0
  75. data/library/opengl/library/jogl_awt.dll +0 -0
  76. data/library/opengl/library/jogl_cg.dll +0 -0
  77. data/library/opengl/library/libgluegen-rt.jnilib +0 -0
  78. data/library/opengl/library/libgluegen-rt.so +0 -0
  79. data/library/opengl/library/libjogl.jnilib +0 -0
  80. data/library/opengl/library/libjogl.so +0 -0
  81. data/library/opengl/library/libjogl_awt.jnilib +0 -0
  82. data/library/opengl/library/libjogl_awt.so +0 -0
  83. data/library/opengl/library/libjogl_cg.jnilib +0 -0
  84. data/library/opengl/library/libjogl_cg.so +0 -0
  85. data/library/opengl/library/opengl.jar +0 -0
  86. data/library/pdf/bin/processing/pdf/PGraphicsPDF.class +0 -0
  87. data/library/pdf/library/itext.jar +0 -0
  88. data/library/pdf/library/pdf.jar +0 -0
  89. data/library/pdf/notes.txt +9 -0
  90. data/library/serial/bin/processing/serial/Serial.class +0 -0
  91. data/library/serial/library/RXTXcomm.jar +0 -0
  92. data/library/serial/library/export.txt +3 -0
  93. data/library/serial/library/librxtxSerial.jnilib +0 -0
  94. data/library/serial/library/librxtxSerial.so +0 -0
  95. data/library/serial/library/rxtxSerial.dll +0 -0
  96. data/library/serial/library/serial.jar +0 -0
  97. data/library/video/bin/processing/video/Capture.class +0 -0
  98. data/library/video/bin/processing/video/Movie.class +0 -0
  99. data/library/video/bin/processing/video/MovieMaker.class +0 -0
  100. data/library/video/library/video.jar +0 -0
  101. data/samples/animator.rb +47 -0
  102. data/samples/circle_collision.rb +213 -0
  103. data/samples/fern.rb +49 -0
  104. data/samples/flight_patterns.rb +64 -0
  105. data/samples/full_screen.rb +35 -0
  106. data/samples/getting_started.rb +43 -0
  107. data/samples/jwishy.rb +85 -0
  108. data/samples/kinetic_type.rb +100 -0
  109. data/samples/learning_processing/ABOUT +11 -0
  110. data/samples/learning_processing/chapter_01/1_stroke_and_fill.rb +34 -0
  111. data/samples/learning_processing/chapter_01/2_nofill.rb +25 -0
  112. data/samples/learning_processing/chapter_01/3_rgb_color.rb +31 -0
  113. data/samples/learning_processing/chapter_01/4_alpha_transparency.rb +36 -0
  114. data/samples/learning_processing/chapter_01/5_zoog.rb +37 -0
  115. data/samples/learning_processing/chapter_02/1_zoog_again.rb +39 -0
  116. data/samples/learning_processing/chapter_03/1_zoog_as_dynamic_sketch.rb +44 -0
  117. data/samples/learning_processing/chapter_03/2_mouse_x_and_mouse_y.rb +26 -0
  118. data/samples/learning_processing/chapter_03/3_zoog_as_dynamic_sketch_with_variation.rb +41 -0
  119. data/samples/learning_processing/chapter_03/4_drawing_a_continuous_line.rb +18 -0
  120. data/samples/learning_processing/chapter_03/5_mouse_pressed_and_key_pressed.rb +29 -0
  121. data/samples/learning_processing/chapter_03/6_interactive_zoog.rb +50 -0
  122. data/samples/learning_processing/chapter_04/1_variable_declaration.rb +24 -0
  123. data/samples/learning_processing/chapter_04/2_using_variables.rb +27 -0
  124. data/samples/learning_processing/chapter_04/3_varying_variables.rb +27 -0
  125. data/samples/learning_processing/chapter_04/4_many_variables.rb +38 -0
  126. data/samples/learning_processing/chapter_04/5_using_system_variables.rb +28 -0
  127. data/samples/learning_processing/chapter_04/6_ellipse_with_variables.rb +24 -0
  128. data/samples/learning_processing/chapter_04/7_filling_variables_with_random_values.rb +27 -0
  129. data/samples/learning_processing/chapter_04/8_variable_zoog.rb +50 -0
  130. data/samples/learning_processing/chapter_05/01_conditionals.rb +31 -0
  131. data/samples/learning_processing/chapter_05/02_more_conditionals.rb +38 -0
  132. data/samples/learning_processing/chapter_05/03_rollovers.rb +34 -0
  133. data/samples/learning_processing/chapter_05/04_hold_down_the_button.rb +33 -0
  134. data/samples/learning_processing/chapter_05/05_button_as_switch.rb +39 -0
  135. data/samples/learning_processing/chapter_05/06_bouncing_ball.rb +33 -0
  136. data/samples/learning_processing/chapter_05/07_bouncing_color.rb +37 -0
  137. data/samples/learning_processing/chapter_05/08_square_following_edge.rb +59 -0
  138. data/samples/learning_processing/chapter_05/09_simple_gravity.rb +43 -0
  139. data/samples/learning_processing/chapter_05/10_zoog_and_conditionals.rb +53 -0
  140. data/samples/learning_processing/chapter_06/01_many_lines.rb +29 -0
  141. data/samples/learning_processing/chapter_06/02_many_lines_with_variables.rb +53 -0
  142. data/samples/learning_processing/chapter_06/03_while_loop.rb +30 -0
  143. data/samples/learning_processing/chapter_06/04_infinite_loop.rb +25 -0
  144. data/samples/learning_processing/chapter_06/05_another_infinite_loop.rb +33 -0
  145. data/samples/learning_processing/chapter_06/06_legs_with_a_for_loop.rb +41 -0
  146. data/samples/learning_processing/chapter_06/07_local_variables.rb +39 -0
  147. data/samples/learning_processing/chapter_06/08_lines_one_at_a_time.rb +30 -0
  148. data/samples/learning_processing/chapter_06/09_simple_while_loop_with_interactivity.rb +41 -0
  149. data/samples/learning_processing/chapter_06/10_zoog_with_arms.rb +56 -0
  150. data/samples/learning_processing/chapter_06/11_multiple_zoogs.rb +46 -0
  151. data/samples/learning_processing/chapter_07/01_defining_a_function.rb +22 -0
  152. data/samples/learning_processing/chapter_07/02_calling_a_function.rb +22 -0
  153. data/samples/learning_processing/chapter_07/03_bouncing_ball_with_functions.rb +49 -0
  154. data/samples/learning_processing/chapter_07/04_function_returns_distance.rb +48 -0
  155. data/samples/learning_processing/chapter_07/05_zoog_with_functions.rb +71 -0
  156. data/samples/learning_processing/chapter_08/01_car_class_and_car_variable.rb +45 -0
  157. data/samples/learning_processing/chapter_08/02_two_car_objects.rb +60 -0
  158. data/samples/learning_processing/chapter_08/03_object_oriented_zoog.rb +81 -0
  159. data/samples/learning_processing/chapter_10/01_catcher.rb +35 -0
  160. data/samples/learning_processing/chapter_10/02_bouncing_ball.rb +44 -0
  161. data/samples/learning_processing/chapter_10/03_bouncing_balls_with_intersection.rb +69 -0
  162. data/samples/learning_processing/chapter_10/04_a_timer.rb +24 -0
  163. data/samples/learning_processing/chapter_10/05_object_oriented_timer.rb +42 -0
  164. data/samples/learning_processing/chapter_10/06_simple_raindrop.rb +23 -0
  165. data/samples/learning_processing/chapter_10/07_drops_one_at_a_time.rb +63 -0
  166. data/samples/learning_processing/chapter_13/02_random_number_distribution.rb +24 -0
  167. data/samples/learning_processing/chapter_13/03_probabilities.rb +33 -0
  168. data/samples/learning_processing/chapter_13/04_perlin_noise.rb +22 -0
  169. data/samples/learning_processing/chapter_13/06_oscillation.rb +29 -0
  170. data/samples/learning_processing/chapter_13/07_wave.rb +31 -0
  171. data/samples/learning_processing/chapter_13/08_recursion.rb +30 -0
  172. data/samples/learning_processing/chapter_13/09_two_dimensional_array.rb +21 -0
  173. data/samples/learning_processing/chapter_13/10_two_dimensional_array_with_objects.rb +54 -0
  174. data/samples/learning_processing/chapter_14/01_growing_rectangle.rb +26 -0
  175. data/samples/learning_processing/chapter_14/02_multiple_translations.rb +37 -0
  176. data/samples/learning_processing/chapter_14/03_depth_rectangle.rb +29 -0
  177. data/samples/learning_processing/chapter_14/04_pyramid_using_beingshape.rb +55 -0
  178. data/samples/learning_processing/chapter_14/05_rotate_rectangle_around_center.rb +28 -0
  179. data/samples/learning_processing/chapter_14/06_rotate_z.rb +24 -0
  180. data/samples/learning_processing/chapter_14/07_rotate_x.rb +24 -0
  181. data/samples/learning_processing/chapter_14/08_rotate_y.rb +24 -0
  182. data/samples/learning_processing/chapter_14/09_rotate_all.rb +24 -0
  183. data/samples/learning_processing/chapter_14/10_draw_pyramid.rb +59 -0
  184. data/samples/learning_processing/chapter_14/12_rotating_one_square.rb +25 -0
  185. data/samples/learning_processing/chapter_14/13_rotating_another_square.rb +25 -0
  186. data/samples/learning_processing/chapter_14/14_rotating_both_squares.rb +43 -0
  187. data/samples/learning_processing/chapter_14/15_rotating_many_things.rb +56 -0
  188. data/samples/learning_processing/chapter_14/16_simple_solar_system.rb +53 -0
  189. data/samples/learning_processing/chapter_14/17_nested_push_and_pop.rb +50 -0
  190. data/samples/learning_processing/chapter_14/18_object_oriented_solar_system.rb +69 -0
  191. data/samples/learning_processing/chapter_15/01_hello_world_image.rb +20 -0
  192. data/samples/learning_processing/chapter_15/02_image_sprite.rb +29 -0
  193. data/samples/learning_processing/chapter_15/03_swapping_images.rb +25 -0
  194. data/samples/learning_processing/chapter_15/04_image_sequence.rb +22 -0
  195. data/samples/learning_processing/chapter_15/05_setting_pixels.rb +19 -0
  196. data/samples/learning_processing/chapter_15/06_pixels_2d.rb +29 -0
  197. data/samples/learning_processing/chapter_15/07_image_pixels.rb +40 -0
  198. data/samples/learning_processing/chapter_15/08_image_brightness.rb +29 -0
  199. data/samples/learning_processing/chapter_15/09_flashlight_effect.rb +42 -0
  200. data/samples/learning_processing/chapter_15/10_brightness_threshold.rb +33 -0
  201. data/samples/learning_processing/chapter_15/11_brightness_threshold_with_filter.rb +20 -0
  202. data/samples/learning_processing/chapter_15/12_pixel_neighbour_differences.rb +43 -0
  203. data/samples/learning_processing/chapter_15/14_pointillism.rb +34 -0
  204. data/samples/learning_processing/chapter_15/15_2d_image_mapped_to_3d.rb +43 -0
  205. data/samples/learning_processing/chapter_15/data/animal0.jpg +0 -0
  206. data/samples/learning_processing/chapter_15/data/animal1.jpg +0 -0
  207. data/samples/learning_processing/chapter_15/data/animal2.jpg +0 -0
  208. data/samples/learning_processing/chapter_15/data/animal3.jpg +0 -0
  209. data/samples/learning_processing/chapter_15/data/animal4.jpg +0 -0
  210. data/samples/learning_processing/chapter_15/data/animal5.jpg +0 -0
  211. data/samples/learning_processing/chapter_15/data/animal6.jpg +0 -0
  212. data/samples/learning_processing/chapter_15/data/face.jpg +0 -0
  213. data/samples/learning_processing/chapter_15/data/mysummervacation.jpg +0 -0
  214. data/samples/learning_processing/chapter_15/data/sunflower.jpg +0 -0
  215. data/samples/learning_processing/chapter_16/01_display_video.rb +25 -0
  216. data/samples/learning_processing/chapter_16/02_manipulate_video_image.rb +24 -0
  217. data/samples/reflection.rb +26 -0
  218. data/samples/simple_buffer.rb +49 -0
  219. data/samples/tree.rb +83 -0
  220. metadata +348 -0
@@ -0,0 +1,37 @@
1
+ require 'ruby-processing'
2
+
3
+ class Zoog < Processing::App
4
+
5
+ def setup
6
+ background 255
7
+ smooth
8
+ ellipse_mode CENTER
9
+ rect_mode CENTER
10
+
11
+ # Body
12
+ stroke 0
13
+ fill 150
14
+ rect 100, 100, 20, 100
15
+
16
+ # Head
17
+ fill 255
18
+ ellipse 100, 70, 60, 60
19
+
20
+ # Eyes
21
+ fill 0
22
+ ellipse 81, 70, 16, 32
23
+ ellipse 119, 70, 16, 32
24
+
25
+ # Legs
26
+ stroke 0
27
+ line 90, 150, 80, 160
28
+ line 110, 150, 120, 160
29
+ end
30
+
31
+ def draw
32
+
33
+ end
34
+
35
+ end
36
+
37
+ Zoog.new :title => "Zoog", :width => 200, :height => 200
@@ -0,0 +1,39 @@
1
+ require 'ruby-processing'
2
+
3
+ class ZoogAgain < Processing::App
4
+
5
+ def setup
6
+ background 255
7
+ smooth
8
+
9
+ # Set ellipses and rects to CENTER mode
10
+ ellipse_mode CENTER
11
+ rect_mode CENTER
12
+
13
+ # Draw Zoog's body
14
+ stroke 0
15
+ fill 150
16
+ rect 100, 100, 20, 100
17
+
18
+ # Draw Zoog's head
19
+ fill 255
20
+ ellipse 100, 70, 60, 60
21
+
22
+ # Draw Zoog's eyes
23
+ fill 0
24
+ ellipse 81, 70, 16, 32
25
+ ellipse 119, 70, 16, 32
26
+
27
+ # Draw Zoog's legs
28
+ stroke 0
29
+ line 90, 150, 80, 160
30
+ line 110, 150, 120, 160
31
+ end
32
+
33
+ def draw
34
+
35
+ end
36
+
37
+ end
38
+
39
+ ZoogAgain.new :title => "Zoog Again", :width => 200, :height => 200
@@ -0,0 +1,44 @@
1
+ require 'ruby-processing'
2
+
3
+ class ZoogAsDynamicSketch < Processing::App
4
+
5
+ # Setup runs first one time.
6
+ # In Ruby-Processing, you never need to call size(),
7
+ # just set the width and height when you instantiate the sketch,
8
+ # at the bottom.
9
+ def setup
10
+
11
+ end
12
+
13
+ # Draw loops continuously until you close the sketch window.
14
+ def draw
15
+ # Draw a white background
16
+ background 255
17
+
18
+ # Set CENTER mode
19
+ ellipse_mode CENTER
20
+ rect_mode CENTER
21
+
22
+ # Draw Zoog's body
23
+ stroke 0
24
+ fill 150
25
+ rect 100, 100, 20, 100
26
+
27
+ # Draw Zoog's head
28
+ fill 255
29
+ ellipse 100, 70, 60, 60
30
+
31
+ # Draw Zoog's eyes
32
+ fill 0
33
+ ellipse 81, 70, 16, 32
34
+ ellipse 119, 70, 16, 32
35
+
36
+ # Draw Zoog's legs
37
+ stroke 0
38
+ line 90, 150, 80, 160
39
+ line 110, 150, 120, 160
40
+ end
41
+
42
+ end
43
+
44
+ ZoogAsDynamicSketch.new :title => "Zoog As Dynamic Sketch", :width => 200, :height => 200
@@ -0,0 +1,26 @@
1
+ require 'ruby-processing'
2
+
3
+ class MouseXAndMouseY < Processing::App
4
+
5
+ def setup
6
+
7
+ end
8
+
9
+ def draw
10
+ # Try moving background to setup and see the difference!
11
+ background 255
12
+
13
+ # Body
14
+ stroke 0
15
+ fill 175
16
+ rect_mode CENTER
17
+
18
+ # mouse_x is a keyword that the sketch replaces with the
19
+ # horizontal position of the mouse.
20
+ # mouse_y gets the vertical position.
21
+ rect mouse_x, mouse_y, 50, 50
22
+ end
23
+
24
+ end
25
+
26
+ MouseXAndMouseY.new :title => "Mouse X And Mouse Y", :width => 200, :height => 200
@@ -0,0 +1,41 @@
1
+ require 'ruby-processing'
2
+
3
+ class ZoogAsDynamicSketchWithVariation < Processing::App
4
+
5
+ def setup
6
+ smooth
7
+ end
8
+
9
+ def draw
10
+ background 255 # Draw a white background
11
+
12
+ # Set ellipses and rects to CENTER mode
13
+ ellipse_mode CENTER
14
+ rect_mode CENTER
15
+
16
+ # Draw Zoog's body
17
+ stroke 0
18
+ fill 150
19
+ # Zoog's body is drawn at the location (mouse_x, mouse_y)
20
+ rect mouse_x, mouse_y, 20, 100
21
+
22
+ # Draw Zoog's head
23
+ stroke 0
24
+ fill 255
25
+ # Zoog's head is drawn above the body at the location (mouse_x, mouse_y - 30)
26
+ ellipse mouse_x, mouse_y - 30, 60, 60
27
+
28
+ # Draw Zoog's eyes
29
+ fill 0
30
+ ellipse 81, 70, 16, 32
31
+ ellipse 119, 70, 16, 32
32
+
33
+ # Draw Zoog's legs
34
+ stroke 0
35
+ line 90, 150, 80, 160
36
+ line 110, 150, 120, 160
37
+ end
38
+
39
+ end
40
+
41
+ ZoogAsDynamicSketchWithVariation.new :title => "Zoog As Dynamic Sketch With Variation", :width => 200, :height => 200
@@ -0,0 +1,18 @@
1
+ require 'ruby-processing'
2
+
3
+ class DrawingAContinuousLine < Processing::App
4
+
5
+ def setup
6
+ background 255
7
+ smooth
8
+ end
9
+
10
+ def draw
11
+ stroke 0
12
+ # Draw a line from the previous mouse location to the current location.
13
+ line pmouse_x, pmouse_y, mouse_x, mouse_y
14
+ end
15
+
16
+ end
17
+
18
+ DrawingAContinuousLine.new :title => "Drawing A Continuous Line", :width => 200, :height => 200
@@ -0,0 +1,29 @@
1
+ require 'ruby-processing'
2
+
3
+ # Click the mouse to draw a square. Hit the space bar to clear the window.
4
+ class MousePressedAndKeyPressed < Processing::App
5
+
6
+ def setup
7
+ background 255
8
+ end
9
+
10
+ def draw
11
+ # Nothing happens in draw in this example!
12
+ end
13
+
14
+ # Whenever the mouse is clicked, the code inside mouse_pressed runs.
15
+ def mouse_pressed
16
+ stroke 0
17
+ fill 175
18
+ rect_mode CENTER
19
+ rect mouse_x, mouse_y, 16, 16
20
+ end
21
+
22
+ # Whenever a key is pressed, the code inside key_pressed runs.
23
+ def key_pressed
24
+ background 255
25
+ end
26
+
27
+ end
28
+
29
+ MousePressedAndKeyPressed.new :title => "Mouse Pressed And Key Pressed", :width => 200, :height => 200
@@ -0,0 +1,50 @@
1
+ require 'ruby-processing'
2
+
3
+ class InteractiveZoog < Processing::App
4
+
5
+ def setup
6
+ smooth
7
+ # The frame rate (like a movie) is set to 30 frames per second
8
+ frame_rate 30
9
+ end
10
+
11
+ def draw
12
+ # draw a white background
13
+ background 255
14
+
15
+ # Set ellipses and rects to CENTER mode
16
+ ellipse_mode CENTER
17
+ rect_mode CENTER
18
+
19
+ # Draw Zoog's body
20
+ stroke 0
21
+ fill 150
22
+ rect mouse_x, mouse_y, 20, 100
23
+
24
+ # Draw Zoog's head
25
+ stroke 0
26
+ fill 255
27
+ ellipse mouse_x, mouse_y - 30, 60, 60
28
+
29
+ # Draw Zoog's eyes
30
+ # The eye color is determined by mouse location.
31
+ fill mouse_x, 0, mouse_y
32
+ ellipse mouse_x - 19, mouse_y - 30, 16, 32
33
+ ellipse mouse_x + 19, mouse_y - 30, 16, 32
34
+
35
+ # Draw Zoog's legs
36
+ stroke 0
37
+ # The legs are drawn according to where the mouse is now and where it used to be.
38
+ line mouse_x - 10, mouse_y + 50, pmouse_x - 10, pmouse_y + 60
39
+ line mouse_x + 10, mouse_y + 50, pmouse_x + 10, pmouse_y + 60
40
+ end
41
+
42
+ def mouse_pressed
43
+ # In Ruby, you can call 'puts' to print to the console.
44
+ # 'print' also works (but doesn't make a new line).
45
+ puts 'Take me to your leader!'
46
+ end
47
+
48
+ end
49
+
50
+ InteractiveZoog.new :title => "Interactive Zoog?", :width => 200, :height => 200
@@ -0,0 +1,24 @@
1
+ require 'ruby-processing'
2
+
3
+ # Ruby has dynamic typing, so you don't have to say
4
+ # what kind of thing a variable is before using it.
5
+ class VariableDeclaration < Processing::App
6
+
7
+ def setup
8
+ count = 0 # count gets assigned 0, an integer (Fixnum)
9
+ letter = 'a' # letter gets the letter 'a', a String
10
+ d = 132.32 # d gets the decimal 132.32, a Float (floating-point number)
11
+ happy = false # happy gets false, a Boolean (true or false)
12
+ x = 4.0 # x gets 4.0, another Float
13
+ y = nil # y gets nil, which stands for nothing
14
+ y = x + 5.2 # assign the value of x plus 5.2 to y
15
+ z = x * y + 15.0 # z gets the value of x times y plus 15.0 (or 51.8)
16
+ end
17
+
18
+ def draw
19
+
20
+ end
21
+
22
+ end
23
+
24
+ VariableDeclaration.new :title => "Variable Declaration and Initialization Examples", :width => 200, :height => 200
@@ -0,0 +1,27 @@
1
+ require 'ruby-processing'
2
+
3
+ class UsingVariables < Processing::App
4
+
5
+ def setup
6
+ # Create two variables, holding integers.
7
+ # These will be instance variables, meaning that you can
8
+ # get at them from any method within this class.
9
+ # Instance variables in Ruby begin with '@'.
10
+
11
+ @circle_x = 100
12
+ @circle_y = 100
13
+ smooth
14
+ end
15
+
16
+ def draw
17
+ background 255
18
+ stroke 0
19
+ fill 175
20
+ # We use the instance variables from setup for the circle.
21
+ # They are available in this method too.
22
+ ellipse @circle_x, @circle_y, 50, 50
23
+ end
24
+
25
+ end
26
+
27
+ UsingVariables.new :title => "Using Variables", :width => 200, :height => 200
@@ -0,0 +1,27 @@
1
+ require 'ruby-processing'
2
+
3
+ class VaryingVariables < Processing::App
4
+
5
+ def setup
6
+ # Declare and initialize two integer instance variables.
7
+ @circle_x = 0
8
+ @circle_y = 100
9
+
10
+ smooth
11
+ end
12
+
13
+ def draw
14
+ background 255
15
+ stroke 0
16
+ fill 175
17
+
18
+ # Use the variables to specify the location of the circle
19
+ ellipse @circle_x, @circle_y, 50, 50
20
+
21
+ # An assignment operation that increments the value of circle_x by 1.
22
+ @circle_x += 1
23
+ end
24
+
25
+ end
26
+
27
+ VaryingVariables.new :title => "Varying Variables", :width => 200, :height => 200
@@ -0,0 +1,38 @@
1
+ require 'ruby-processing'
2
+
3
+ class ManyVariables < Processing::App
4
+
5
+ def setup
6
+ # We've got 8 variables now! They're all Floats.
7
+ @circle_x, @circle_y = 0.0, 0.0
8
+ @circle_w, @circle_h = 50.0, 100.0
9
+ @circle_stroke = 255.0
10
+ @circle_fill = 0.0
11
+ @background_color = 255.0
12
+ @change = 0.5
13
+
14
+ smooth
15
+ end
16
+
17
+ def draw
18
+ # Draw the background and the ellipse.
19
+ # Variables are used for everything:
20
+ # background, stroke, fill, location and size.
21
+ background @background_color
22
+ stroke @circle_stroke
23
+ fill @circle_fill
24
+ ellipse @circle_x, @circle_y, @circle_w, @circle_h
25
+
26
+ # Change the values of all variables.
27
+ # The variable change is used to update the others.
28
+ @circle_x += @change
29
+ @circle_y += @change
30
+ @circle_w += @change
31
+ @circle_h -= @change
32
+ @circle_stroke -= @change
33
+ @circle_fill += @change
34
+ end
35
+
36
+ end
37
+
38
+ ManyVariables.new :title => "Many Variables", :width => 200, :height => 200
@@ -0,0 +1,28 @@
1
+ require 'ruby-processing'
2
+
3
+ class UsingSystemVariables < Processing::App
4
+
5
+ def setup
6
+ smooth
7
+ end
8
+
9
+ def draw
10
+ background 100
11
+ stroke 255
12
+
13
+ # frame_count is used to color a rectangle
14
+ fill(frame_count / 2)
15
+ rect_mode CENTER
16
+
17
+ # The rectangle will always be in the middle of the window
18
+ # if it is located at (width/2, height/2)
19
+ rect(width/2, height/2, mouse_x + 10, mouse_y + 10)
20
+ end
21
+
22
+ def key_pressed
23
+ puts key
24
+ end
25
+
26
+ end
27
+
28
+ UsingSystemVariables.new :title => "Using System Variables", :width => 200, :height => 200