ruby-processing 1.0.1

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.
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,29 @@
1
+ require 'ruby-processing'
2
+
3
+ class Pixels2dSketch < Processing::App
4
+
5
+ def setup
6
+ # load the pixels array
7
+ load_pixels
8
+ # Two loops allow us to visit every column (x) and every row (y).
9
+ # Loop through every pixel column
10
+ width.times do |x|
11
+ # Loop through every pixel row
12
+ height.times do |y|
13
+ # Use the formula to find the 1D location
14
+ # The location in the pixel array is calculated via our formula: 1D pixel location = x + y * width
15
+ loc = x + y * width
16
+ # We use the even-or-odd-ness of the column number (x) to determine whether the color should be black or white.
17
+ pixels[loc] = (x % 2 == 0) ? color(255) : color(0)
18
+ end
19
+ end
20
+ # update the pixels on screen
21
+ update_pixels
22
+ end
23
+
24
+
25
+ end
26
+
27
+ Pixels2dSketch.new :title => "Pixels 2d", :width => 200, :height => 200
28
+
29
+
@@ -0,0 +1,40 @@
1
+ require 'ruby-processing'
2
+
3
+ class ImagePixelsSketch < Processing::App
4
+
5
+ def setup
6
+ @image = load_image 'sunflower.jpg'
7
+ end
8
+
9
+ def draw
10
+ # load the pixels array
11
+ load_pixels
12
+ # Two loops allow us to visit every column (x) and every row (y).
13
+ # Loop through every pixel column
14
+ width.times do |x|
15
+ # Loop through every pixel row
16
+ height.times do |y|
17
+ # Use the formula to find the 1D location
18
+ loc = x + y * width # The location in the pixel array is calculated via our formula: 1D pixel location = x + y * width
19
+
20
+ # The functions red, green, and blue pull out the three color components from a pixel.
21
+ r = red(@image.pixels[loc])
22
+ g = green(@image.pixels[loc])
23
+ b = blue(@image.pixels[loc])
24
+
25
+ # Image Processing would go here
26
+ # If we were to change the RGB values, we would do it here, before setting the pixel in the display window.
27
+
28
+ # Set the display pixel to the image pixel
29
+ pixels[loc] = color(r,g,b)
30
+ end
31
+ end
32
+ # update the pixels on screen
33
+ update_pixels
34
+ end
35
+
36
+ end
37
+
38
+ ImagePixelsSketch.new :title => "Image Pixels", :width => 200, :height => 200
39
+
40
+
@@ -0,0 +1,29 @@
1
+ require 'ruby-processing'
2
+
3
+ class ImageBrightnessSketch < Processing::App
4
+
5
+ def setup
6
+ @image = load_image 'sunflower.jpg'
7
+ # Let's grab the red, green and blue component of each pixel of the image to start with.
8
+ @image_pixels = @image.pixels.map {|p| [red(p), green(p), blue(p)]}
9
+ end
10
+
11
+ def draw
12
+ # We calculate a multiplier ranging from 0.0 to 8.0 based on mouseX position.
13
+ # That multiplier changes the RGB value of each pixel.
14
+ adjustment = (mouse_x.to_f / width) * 8.0
15
+ load_pixels # load the pixels array
16
+
17
+ # And here's a modified Ruby way to do the Java equivalent
18
+ pixels.size.times do |i|
19
+ pixels[i] = color(*@image_pixels[i].map {|rgb| rgb * adjustment })
20
+ end
21
+
22
+ update_pixels
23
+ end
24
+
25
+ end
26
+
27
+ ImageBrightnessSketch.new :title => "Image Brightness", :width => 200, :height => 200
28
+
29
+
@@ -0,0 +1,42 @@
1
+ require 'ruby-processing'
2
+
3
+ class FlashlightEffectSketch < Processing::App
4
+
5
+ def setup
6
+ @image = load_image 'sunflower.jpg'
7
+ # Let's grab the red, green and blue component of each pixel of the image to start with.
8
+ @image_pixels = @image.pixels.map {|p| [red(p), green(p), blue(p)]}
9
+ end
10
+
11
+ def draw
12
+ load_pixels # Load the pixels array
13
+ # Two loops allow us to visit every column (x) and every row (y).
14
+ # Loop through every pixel column
15
+ width.times do |x|
16
+ # Loop through every pixel row
17
+ height.times do |y|
18
+ # Use the formula to find the 1D location
19
+ loc = x + y * width # The location in the pixel array is calculated via our formula: 1D pixel location = x + y * width
20
+
21
+ # Calculate an amount to change brightness
22
+ # based on proximity to the mouse
23
+ distance = dist(x, y, mouseX, mouseY)
24
+
25
+ # The closer the pixel is to the mouse, the lower the value of "distance"
26
+ # We want closer pixels to be brighter, however, so we invert the value with the formula: adjustment = (50-distance)/50
27
+ # Pixels with a distance of 50 (or greater) have a brightness of 0.0 (or negative which is equivalent to 0 here)
28
+ # Pixels with a distance of 0 have a brightness of 1.0.
29
+ adjustment = (50 - distance) / 50
30
+
31
+ # Set the display pixel to the image pixel
32
+ pixels[loc] = color(*@image_pixels[loc].map {|rgb| rgb * adjustment })
33
+ end
34
+ end
35
+ update_pixels
36
+ end
37
+
38
+ end
39
+
40
+ FlashlightEffectSketch.new :title => "Flashlight Effect", :width => 200, :height => 200
41
+
42
+
@@ -0,0 +1,33 @@
1
+ require 'ruby-processing'
2
+
3
+ class BrightnessThresholdSketch < Processing::App
4
+
5
+ def setup
6
+ @source = load_image 'sunflower.jpg'
7
+ @destination = create_image @source.width, @source.height, RGB
8
+ end
9
+
10
+ def draw
11
+ threshold = 127
12
+ # We are going to look at both image's pixels
13
+ @source.load_pixels
14
+ @destination.load_pixels
15
+
16
+ @source.width.times do |x|
17
+ @source.height.times do |y|
18
+ loc = x + y*@source.width;
19
+ # Test the brightness against the threshold
20
+ @destination.pixels[loc] = (brightness(@source.pixels[loc]) > threshold) ? color(255) : color(0)
21
+ end
22
+ end
23
+
24
+ # We changed the pixels in @destination
25
+ @destination.update_pixels
26
+ # Display the @destination
27
+ image @destination, 0, 0
28
+ end
29
+
30
+ end
31
+
32
+ BrightnessThresholdSketch.new :title => "Brightness Threshold", :width => 200, :height => 200
33
+
@@ -0,0 +1,20 @@
1
+ require 'ruby-processing'
2
+
3
+ class BrightnessThresholdWithFilterSketch < Processing::App
4
+
5
+ def setup
6
+ @img = load_image 'sunflower.jpg'
7
+ end
8
+
9
+ def draw
10
+ # Draw the image
11
+ image @img, 0, 0
12
+ # Filter the window with a threshold effect
13
+ # 0.5 means threshold is 50% brightness
14
+ filter THRESHOLD, 0.5
15
+ end
16
+
17
+ end
18
+
19
+ BrightnessThresholdWithFilterSketch.new :title => "Brightness Threshold With Filter", :width => 200, :height => 200
20
+
@@ -0,0 +1,43 @@
1
+ require 'ruby-processing'
2
+
3
+ class PixelNeighbourDifferencesSketch < Processing::App
4
+
5
+ def setup
6
+ @img = load_image 'sunflower.jpg'
7
+ @destination = create_image @img.width, @img.height, RGB
8
+ end
9
+
10
+ def draw
11
+ # We are going to look at both image's pixels
12
+ @img.load_pixels
13
+ @destination.load_pixels
14
+
15
+ # Since we are looking at left neighbors
16
+ # We skip the first column
17
+ (1...width).each do |x|
18
+ (0...height).each do |y|
19
+ # Pixel location and color
20
+ loc = x + y * @img.width
21
+ pix = @img.pixels[loc]
22
+
23
+ # Pixel to the left location and color
24
+ left_loc = (x - 1) + y * @img.width
25
+ left_pix = @img.pixels[left_loc]
26
+
27
+ # New color is difference between pixel and left neighbor
28
+ diff = (brightness(pix) - brightness(left_pix)).abs
29
+ @destination.pixels[loc] = color(diff)
30
+ end
31
+ end
32
+
33
+ # We changed the pixels in @destination
34
+ @destination.update_pixels
35
+ # Display the @destination
36
+ image @destination, 0, 0
37
+ end
38
+
39
+ end
40
+
41
+ PixelNeighbourDifferencesSketch.new :title => "Pixel Neighbour Differences", :width => 200, :height => 200
42
+
43
+
@@ -0,0 +1,34 @@
1
+ require 'ruby-processing'
2
+
3
+ class PointillismSketch < Processing::App
4
+
5
+ def setup
6
+ @pointillize = 10
7
+ @img = load_image 'sunflower.jpg'
8
+ background 255
9
+ frame_rate 200 # Let's run this one as fast as we can.
10
+ no_stroke
11
+ smooth
12
+ end
13
+
14
+ def draw
15
+ # Pick a random point
16
+ x, y = rand(width), rand(height)
17
+ loc = x + y * width
18
+
19
+ # Look up the RGB color in the source image
20
+ load_pixels
21
+ pixel = @img.pixels[loc]
22
+ r, g, b = red(pixel), green(pixel), blue(pixel)
23
+
24
+ # Draw an ellipse at that location with that color
25
+ fill r, g, b, 100
26
+ # Back to shapes! Instead of setting a pixel, we use the color from a pixel to draw a circle.
27
+ ellipse x, y, @pointillize, @pointillize
28
+ end
29
+
30
+ end
31
+
32
+ PointillismSketch.new :title => "Pointillism", :width => 200, :height => 200
33
+
34
+
@@ -0,0 +1,43 @@
1
+ require 'ruby-processing'
2
+
3
+ class TwoDMappedTo3dSketch < Processing::App
4
+
5
+ def setup
6
+ @cellsize = 2
7
+ @img = load_image 'sunflower.jpg' # Load the image
8
+ @img.load_pixels
9
+ @pixels = @img.pixels
10
+ @cols = width / @cellsize # Calculate number of columns
11
+ @rows = height / @cellsize # Calculate number of rows
12
+ render_mode P3D
13
+ no_stroke
14
+ rect_mode CENTER
15
+ end
16
+
17
+ def draw
18
+ background 255
19
+ @cols.times do |i| # Begin loop for columns
20
+ x = i * @cellsize + @cellsize / 2 # x position
21
+ @rows.times do |j| # Begin loop for rows
22
+ y = j * @cellsize + @cellsize / 2 # y position
23
+ loc = x + y * width # Pixel array location
24
+ c = @pixels[loc] # Grab the color
25
+
26
+ # Calculate a z position as a function of mouse_x and pixel brightness
27
+ z = (mouse_x/width.to_f) * brightness(@pixels[loc]) - 100.0
28
+
29
+ # Translate to the location, set fill and stroke, and draw the rect
30
+ push_matrix
31
+ translate x, y, z
32
+ fill c
33
+ rect 0, 0, @cellsize, @cellsize
34
+ pop_matrix
35
+ end
36
+ end
37
+ end
38
+
39
+ end
40
+
41
+ TwoDMappedTo3dSketch.new :title => "2d Mapped To 3d", :width => 200, :height => 200
42
+
43
+
@@ -0,0 +1,25 @@
1
+ require 'ruby-processing'
2
+
3
+ class CaptureVideoSketch < Processing::App
4
+
5
+ # Step 1. Import the video library
6
+ load_library "video"
7
+ # We need the video classes to be included here.
8
+ include_package "processing.video"
9
+
10
+ def setup
11
+ # Step 2. Declare a Capture object
12
+ @video = Capture.new(self, width, height, 30)
13
+ end
14
+
15
+ def draw
16
+ # Step 3 and 4: Read from the camera if it's available.
17
+ @video.read if @video.available
18
+
19
+ # Step 5. Display the video image.
20
+ image @video, 0, 0
21
+ end
22
+
23
+ end
24
+
25
+ CaptureVideoSketch.new :title => "Capture Video", :width => 320, :height => 240
@@ -0,0 +1,24 @@
1
+ require 'ruby-processing'
2
+
3
+ class ManipulateVideoImageSketch < Processing::App
4
+
5
+ load_library "video"
6
+ include_package "processing.video"
7
+
8
+ def setup
9
+ @video = Capture.new(self, width, height, 30)
10
+ end
11
+
12
+ def draw
13
+ @video.read if @video.available
14
+
15
+ # Tinting using mouse location
16
+ tint mouse_x, mouse_y, 255
17
+
18
+ # A video image can also be tinted and resized just as with a PImage.
19
+ image @video, 0, 0, mouse_x, mouse_y
20
+ end
21
+
22
+ end
23
+
24
+ ManipulateVideoImageSketch.new :title => "Manipulate Video Image", :width => 320, :height => 240
@@ -0,0 +1,26 @@
1
+ # Taken from the Processing Examples.
2
+
3
+ require 'ruby-processing'
4
+
5
+ class Reflection < Processing::App
6
+
7
+ def setup
8
+ render_mode(P3D)
9
+ no_stroke
10
+ color_mode(RGB, 1)
11
+ fill 0.4
12
+ end
13
+
14
+ def draw
15
+ background 0
16
+ translate( width/2, height/2 )
17
+ light_specular(1, 1, 1)
18
+ directional_light(0.8, 0.8, 0.8, 0, 0, -1)
19
+ s = mouse_x.to_f / width.to_f
20
+ specular s, s, s
21
+ sphere 50
22
+ end
23
+
24
+ end
25
+
26
+ Reflection.new(:width => 200, :height => 200, :title => "Reflection")
@@ -0,0 +1,49 @@
1
+ require 'ruby-processing'
2
+
3
+ class SimpleBuffer < Processing::App
4
+ def setup
5
+
6
+ # With Processing, buffers allow you to draw off-screen to an image,
7
+ # and then use that image in your sketch. This can speed up rendering
8
+ # times quite a bit, as it's not only faster to draw off-screen, but
9
+ # it also allows you to redraw only portions of the screen.
10
+
11
+ # Ruby-Processing provides a convenience method, "buffer", which
12
+ # sets up a buffer for you with the same width and height and
13
+ # renderer as the current sketch, and yields it to you. It also
14
+ # takes care of calling begin_draw and end_draw at the start and
15
+ # end of the block. Use it like so:
16
+
17
+ @buffer = buffer do |b|
18
+ b.no_stroke
19
+ b.fill 255, 0, 0
20
+ b.rect 100, 200, 100, 100
21
+ end
22
+
23
+ # Those lines are equivalent to the following lines:
24
+
25
+ @buffer_2 = create_graphics(500, 500, P3D)
26
+ @buffer_2.begin_draw
27
+ @buffer_2.no_stroke
28
+ @buffer_2.fill(255, 0, 0)
29
+ @buffer_2.rect(100, 200, 100, 100)
30
+ @buffer_2.end_draw
31
+
32
+ # If you'd like to set the size or renderer for the buffer block,
33
+ # just pass it in like normal:
34
+
35
+ @buffer_3 = buffer(150, 150, P3D) do |b|
36
+ # b.whatever goes here.
37
+ end
38
+
39
+ # And now we go ahead and grab the rendered image from the first buffer.
40
+ @img = @buffer.get(0, 0, @buffer.width, @buffer.height)
41
+ end
42
+
43
+ def draw
44
+ background 0
45
+ image @img, frame_count, 0
46
+ end
47
+ end
48
+
49
+ SimpleBuffer.new :title => "Simple Buffer", :width => 500, :height => 500