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
data/CHANGELOG ADDED
@@ -0,0 +1,137 @@
1
+ v1.0.1 Gemmin' it up.
2
+ * The smallest version bump is the biggest change:
3
+ Ruby-Processing has undergone a great refactor, kicked off by
4
+ Peter Gassner's initial efforts to make a gem out of it. Now
5
+ available as a real RubyGem.
6
+
7
+ * Changes all around: The main interface to Ruby-Processing is now
8
+ through the 'rp5' command. Try rp5 --help to get started.
9
+
10
+ * has_slider has been superseded by control_panel, a more full-
11
+ fledged library for controlling aspects of your sketch. Read
12
+ how to use it on the wiki, or check out jwishy.rb
13
+
14
+ v1.0. Ruby-Processing goes 1.0 with Processing 1.0
15
+ * Processing updated to 1.0.1 (congrats to the Processing team),
16
+ and JRuby updated to the latest trunk. Most sketches run a good
17
+ bit faster now.
18
+
19
+ * Ruby-Processing now comes with many default libraries: Boids, DXF,
20
+ Javascript, Minim, Net, OpenGL, PDF, Serial, Slider, and Video
21
+ are now included in the download.
22
+
23
+ * has_slider moved out into an included ruby library.
24
+
25
+ v0.9. Multi-platform Application export, live coding, and more.
26
+ * Inspired by NodeBox, Ruby-Processing now sports the ability
27
+ to have sliders control numeric variables in your sketches.
28
+ If you're using an instance variable, say, @speed, to control
29
+ the speed of your sketch.
30
+
31
+ has_slider :speed
32
+
33
+ Will bring up a panel alongside with a slider that controls
34
+ the speed. It can take a range of values as an optional parameter.
35
+ Check out and run jwishy.rb for an example.
36
+
37
+ * Multi-platform app export! Exporting your Ruby-Processing
38
+ apps will now create executable apps for Mac/Windows/Linux.
39
+
40
+ * Live coding support. Now you can do script/live path/to/sketch.rb
41
+ to open up an interactive session with your sketch available
42
+ as $app.
43
+
44
+ * Nick Sieger donated an additional sample.
45
+
46
+ v0.8. Exporting Applications
47
+ * Ruby-Processing can now export Mac applications! Running
48
+ script/application my_sketch.rb will create MySketch.app,
49
+ complete with all of its data and libraries. If you have
50
+ a .icns file inside of your data folder, it will become
51
+ the app's icon.
52
+
53
+ * Added a mathematical Fern sample. It's a port of Luis
54
+ Correia's java original, with algorithms from Wikipedia.
55
+
56
+ * Sketches now have a library_loaded? method, so that you can
57
+ check if a library has been started successfully, and
58
+ conditionally enable things. (Good for OpenGL.)
59
+
60
+ * The Boids library is now about 40% faster. It also comes with
61
+ an example in library/boids/samples.
62
+
63
+ * Specs have been started both for exporting and for Ruby-
64
+ Processing itself.
65
+
66
+ v0.7. Flocking Boids and OpenGL Applets
67
+ * Thanks to MenTaLguY, once again, for work on the JRubyApplet, OpenGL
68
+ is now a first-class citizen. If you're using OpenGL in your sketch,
69
+ the applet exporter should just work. It has also been moved and
70
+ renamed, so now you can use it like:
71
+
72
+ script/applet my_sketch.rb
73
+
74
+ * An app generator has been added for getting started. It'll give you
75
+ a template for an empty Ruby-Processing sketch, with setup and draw
76
+ methods and all that. Usage:
77
+
78
+ script/generate my_sketch 800 600
79
+
80
+ Will create a file called my_sketch.rb, with a title of "My Sketch",
81
+ 800 pixels wide and 600 pixels tall. Width and height are optional.
82
+
83
+ * Ruby-Processing now includes its first pure-Ruby library, a port
84
+ of Tom de Smedt's "Boids", for algorithmic flocking.
85
+
86
+ v0.6. Generating Applets
87
+ * Now we're baking up some applet pie. The applet_tree script will
88
+ take your Ruby-Processing sketch, export it as an applet, and
89
+ generate an HTML page for you to post. It's way easier now than it
90
+ would have been before. (thanks to MenTaLguY.) Use it like so:
91
+
92
+ ./applet_tree my_sketch.rb
93
+
94
+ But there are caveats: Applets don't work with native libraries, so
95
+ no OpenGL. If you're requiring other files that aren't part of the
96
+ standard Ruby distro, you'll need to include them as libraries, which
97
+ means: Drop them in a folder inside of "library". Use
98
+ load_ruby_library("folder_name") or load_java_library() to load 'em.
99
+ These methods replace the previous load_library(). Ruby libs will
100
+ load the .rb with the same name as the folder. Java libs will just
101
+ load up all of the .jars in the folder.
102
+
103
+ Demos — all of the standard samples are available as applets:
104
+ http://fiercefrontiers.com/applets/jwishy/
105
+ http://fiercefrontiers.com/applets/tree/
106
+ http://fiercefrontiers.com/applets/circle_collision/
107
+ http://fiercefrontiers.com/applets/reflection/
108
+
109
+
110
+ v0.5. With Native Libraries
111
+ * Ruby-Processing gets easy native library support. Now you can take
112
+ Processing libraries, drop them in the library folder, and load them
113
+ up like so (inside your sketch):
114
+
115
+ load_library "opengl"
116
+
117
+ It works by loading up all of the .jars in that folder, and setting
118
+ the java.library.path to that folder, so that the native extensions
119
+ can be found.
120
+
121
+ * Full Screen OpenGL demo added, but you'll need to copy over the
122
+ OpenGL library to use it.
123
+
124
+ v0.4. Going Fullscreen
125
+ * Ruby-Processing goes fullscreen. Just pass :full_screen => true
126
+ into the options when you’re starting up your app. Like so:
127
+
128
+ MyApp.new(:title => "MyApp", :full_screen => true)
129
+
130
+ * Because Processing has just so many methods, you can now search
131
+ through them: find_method "method_name"
132
+
133
+ v0.3. First Real Release
134
+ * Processing::App.current will give you a handle on the app. (Useful
135
+ in jirb).
136
+ * samples/jwishy.rb has some new hooks for live coding.
137
+ * circle_collision and tree samples added (Joe Holt)
data/LICENSE ADDED
@@ -0,0 +1,37 @@
1
+ Ruby-Processing is released under the MIT License.
2
+ You can do pretty much whatever you'd like with it.
3
+
4
+ ====================================================
5
+
6
+ Copyright (c) 2008 omygawshkenas
7
+
8
+ Permission is hereby granted, free of charge,
9
+ to any person obtaining a copy of this software
10
+ and associated documentation files (the "Software"),
11
+ to deal in the Software without restriction,
12
+ including without limitation the rights to use,
13
+ copy, modify, merge, publish, distribute, sublicense,
14
+ and/or sell copies of the Software, and to permit
15
+ persons to whom the Software is furnished to do so,
16
+ subject to the following conditions:
17
+
18
+ The above copyright notice and this permission
19
+ notice shall be included in all copies or substantial
20
+ portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY
23
+ OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24
+ LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27
+ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
28
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
29
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE
30
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31
+
32
+ ====================================================
33
+
34
+ Ruby-Processing also distributes core components
35
+ of both JRuby and Processing, which are licensed
36
+ under the GNU Lesser General Public License.
37
+
data/README ADDED
@@ -0,0 +1,61 @@
1
+ =
2
+ ____ _ ____ _
3
+ | _ \ _ _| |__ _ _ | _ \ _ __ ___ ___ ___ ___ ___(_)_ __ __ _
4
+ | |_) | | | | '_ \| | | |_____| |_) | '__/ _ \ / __/ _ \/ __/ __| | '_ \ / _` |
5
+ | _ <| |_| | |_) | |_| |_____| __/| | | (_) | (_| __/\__ \__ \ | | | | (_| |
6
+ |_| \_\\__,_|_.__/ \__, | |_| |_| \___/ \___\___||___/___/_|_| |_|\__, |
7
+ |___/ |___/
8
+
9
+
10
+ Ruby-Processing is a Ruby wrapper for the Processing code art framework. It's
11
+ this thin little shim that squeezes between Processing and JRuby, passing
12
+ along some neat goodies like:
13
+
14
+ * Applet and Application exporting of your sketches. Hand them out to
15
+ your party guests, ready-to-run.
16
+
17
+ * Live Coding via JRuby's IRB. Loads in your sketch so you can futz with
18
+ variables and remake methods on the fly.
19
+
20
+ * A "Control Panel" library, so that you can easily create sliders, buttons,
21
+ checkboxes and drop-down menus, and hook them into your sketch's instance
22
+ variables.
23
+
24
+ * "Watch" mode, where Ruby-Processing keeps an eye on your sketch and reloads
25
+ it from scratch every time you make a change. A pretty nice REPL-ish way
26
+ to work on your Processing sketches.
27
+
28
+ If some quality time with Ruby is your idea of a pleasant afternoon, or you
29
+ harbor ambitions of entering the fast-paced and not altogether cutthroat world
30
+ of Code Art, then Ruby-Processing is probably something you should try on for
31
+ size. You can grab it as a gem:
32
+
33
+ sudo gem install ruby-processing
34
+
35
+
36
+ ~ But Processing? ~
37
+
38
+ Processing is an MIT-developed framework for making little code artifacts,
39
+ animations, visualizations, and the like, developed originally by Ben Fry
40
+ and Casey Reas, supported by a small army of open-source contributors.
41
+ Processing has become a sort of standard for visually-oriented programming,
42
+ strongly influencing the designs of Nodebox, Shoes, Arduino, and other kindred
43
+ projects. For more information, take a look at http://processing.org/
44
+
45
+
46
+ ~ What does it look like? How does it smell? ~
47
+
48
+ Processing provides a tidy API, with a bunch of handy methods you can call
49
+ from Ruby-Processing. Here's a smattering:
50
+
51
+ alpha, arc, background, blend, blue, ellipse, frame_rate, hue, lerp,
52
+ load_image, load_pixels, mouse_pressed, noise, rect, saturation, shape,
53
+ smooth, text_align, translate, triangle...
54
+
55
+ And so on, and so forth. See the full list here:
56
+ http://www.processing.org/reference/index_ext.html
57
+
58
+ ~ How can I learn more? ~
59
+
60
+ For full, up-to-date info, always check the wiki:
61
+ http://wiki.github.com/jashkenas/ruby-processing
data/bin/rp5 ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/ruby-processing")
4
+ Processing::Runner.execute
data/lib/core/core.jar ADDED
Binary file
Binary file
@@ -0,0 +1,27 @@
1
+ # Ruby-Processing is for Code Art.
2
+ # Send suggestions, ideas, and hate-mail to jashkenas [at] gmail.com
3
+ # Also, send samples and libraries.
4
+
5
+ unless defined? RP5_ROOT
6
+ $LOAD_PATH << File.expand_path(File.dirname(__FILE__))
7
+ RP5_ROOT = File.expand_path(File.dirname(__FILE__) + "/../")
8
+ end
9
+
10
+ require 'ruby-processing/helpers/string'
11
+
12
+ # The top-level namespace, a home for all Ruby-Processing classes.
13
+ module Processing
14
+ VERSION = [1,0,1]
15
+
16
+ # Returns the current version of Ruby-Processing.
17
+ def self.version
18
+ VERSION.join('.')
19
+ end
20
+
21
+ autoload :App, 'ruby-processing/app'
22
+ autoload :Runner, 'ruby-processing/runner'
23
+ autoload :Creator, 'ruby-processing/exporters/creator'
24
+ autoload :BaseExporter, 'ruby-processing/exporters/base_exporter'
25
+ autoload :AppletExporter, 'ruby-processing/exporters/applet_exporter'
26
+ autoload :ApplicationExporter, 'ruby-processing/exporters/application_exporter'
27
+ end
@@ -0,0 +1,358 @@
1
+ # This class is a thin wrapper around Processing's PApplet.
2
+ # Most of the code here is for interfacing with Swing,
3
+ # web applets, going fullscreen and so on.
4
+
5
+ require 'java'
6
+
7
+ module Processing
8
+
9
+ # Conditionally load core.jar
10
+ require "#{RP5_ROOT}/lib/core/core.jar" unless Object.const_defined?(:JRUBY_APPLET)
11
+ include_package "processing.core"
12
+
13
+ # This is the main Ruby-Processing class, and is what you'll
14
+ # inherit from when you create a sketch. This class can call
15
+ # all of the methods available in Processing, and has two
16
+ # mandatory methods, 'setup' and 'draw', both of which you
17
+ # should define in your sketch. 'setup' will be called one
18
+ # time when the sketch is first loaded, and 'draw' will be
19
+ # called constantly, for every frame.
20
+ class App < PApplet
21
+ include Math
22
+
23
+ include_class "javax.swing.JFrame"
24
+
25
+ # Alias some methods for familiarity for Shoes coders.
26
+ attr_accessor :frame, :title
27
+ alias_method :oval, :ellipse
28
+ alias_method :stroke_width, :stroke_weight
29
+ alias_method :rgb, :color
30
+ alias_method :gray, :color
31
+
32
+ # Watch the definition of these methods, to make sure
33
+ # that Processing is able to call them during events.
34
+ METHODS_TO_WATCH_FOR = {
35
+ :mouse_pressed => :mousePressed,
36
+ :mouse_dragged => :mouseDragged,
37
+ :mouse_clicked => :mouseClicked,
38
+ :mouse_moved => :mouseMoved,
39
+ :mouse_released => :mouseReleased,
40
+ :key_pressed => :keyPressed,
41
+ :key_released => :keyReleased,
42
+ :key_typed => :keyTyped
43
+ }
44
+
45
+
46
+ def self.method_added(method_name) #:nodoc:
47
+ if METHODS_TO_WATCH_FOR.keys.include?(method_name)
48
+ alias_method METHODS_TO_WATCH_FOR[method_name], method_name
49
+ end
50
+ end
51
+
52
+
53
+ # Class methods that we should make available in the instance.
54
+ [:map, :pow, :norm, :lerp, :second, :minute, :hour, :day, :month, :year,
55
+ :sq, :constrain, :dist, :blend_color].each do |meth|
56
+ method = <<-EOS
57
+ def #{meth}(*args)
58
+ self.class.#{meth}(*args)
59
+ end
60
+ EOS
61
+ eval method
62
+ end
63
+
64
+
65
+ def self.current=(app); @current_app = app; end
66
+ def self.current; @current_app; end
67
+
68
+
69
+ # Are we running inside an applet?
70
+ def self.online?
71
+ @online ||= Object.const_defined?(:JRUBY_APPLET)
72
+ end
73
+ def online?; self.class.online?; end
74
+
75
+
76
+ # Detect if a library has been loaded (for conditional loading)
77
+ @@loaded_libraries = Hash.new(false)
78
+ def self.library_loaded?(folder)
79
+ @@loaded_libraries[folder.to_sym]
80
+ end
81
+ def library_loaded?(folder); self.class.library_loaded?(folder); end
82
+
83
+
84
+ # Load a list of Ruby or Java libraries (in that order)
85
+ # Usage: load_libraries :opengl, :boids
86
+ #
87
+ # If a library is put into a 'library' folder next to the sketch it will
88
+ # be used instead of the library that ships with Ruby-Processing.
89
+ def self.load_libraries(*args)
90
+ args.each {|lib| load_ruby_library(lib) || load_java_library(lib) }
91
+ end
92
+ def self.load_library(*args); self.load_libraries(*args); end
93
+
94
+ # For pure ruby libraries.
95
+ # The library should have an initialization ruby file
96
+ # of the same name as the library folder.
97
+ def self.load_ruby_library(dir)
98
+ dir = dir.to_sym
99
+ return true if @@loaded_libraries[dir]
100
+ return @@loaded_libraries[dir] = (require "library/#{dir}/#{dir}") if online?
101
+ local_path = "#{Dir.pwd}/library/#{dir}"
102
+ gem_path = "#{RP5_ROOT}/library/#{dir}"
103
+ path = File.exists?(local_path) ? local_path : gem_path
104
+ return false unless (File.exists?("#{path}/#{dir}.rb"))
105
+ return @@loaded_libraries[dir] = (require "#{path}/#{dir}")
106
+ end
107
+
108
+
109
+ # For pure java libraries, such as the ones that are available
110
+ # on this page: http://processing.org/reference/libraries/index.html
111
+ #
112
+ # P.S. -- Loading libraries which include native code needs to
113
+ # hack the Java ClassLoader, so that you don't have to
114
+ # futz with your PATH. But it's probably bad juju.
115
+ def self.load_java_library(dir)
116
+ dir = dir.to_sym
117
+ return true if @@loaded_libraries[dir]
118
+ return @@loaded_libraries[dir] = !!(JRUBY_APPLET.get_parameter("archive").match(%r(#{dir}))) if online?
119
+ local_path = "#{Dir.pwd}/library/#{dir}"
120
+ gem_path = "#{RP5_ROOT}/library/#{dir}"
121
+ path = File.exists?(local_path) ? local_path : gem_path
122
+ jars = Dir.glob("#{path}/**/*.jar")
123
+ return false if jars.empty?
124
+ jars.each {|jar| require jar }
125
+ # Here goes...
126
+ library_path = java.lang.System.getProperty("java.library.path")
127
+ new_library_path = [path, "#{path}/library", library_path].join(java.io.File.pathSeparator)
128
+ java.lang.System.setProperty("java.library.path", new_library_path)
129
+ field = java.lang.Class.for_name("java.lang.ClassLoader").get_declared_field("sys_paths")
130
+ if field
131
+ field.accessible = true
132
+ field.set(java.lang.Class.for_name("java.lang.System").get_class_loader, nil)
133
+ end
134
+ return @@loaded_libraries[dir] = true
135
+ end
136
+
137
+
138
+ def self.has_slider(*args) #:nodoc:
139
+ raise "has_slider has been replaced with a nicer control_panel library. Check it out."
140
+ end
141
+
142
+
143
+ # Used by the Processing::Watcher to completely remove all
144
+ # traces of the current sketch, so that it can be loaded afresh.
145
+ def self.wipe_out_current_app!
146
+ app = Processing::App.current
147
+ return unless app
148
+ app_class_name = app.class.to_s.to_sym
149
+ app.close
150
+ Object.send(:remove_const, app_class_name)
151
+ end
152
+
153
+
154
+ # When you make a new sketch, you pass in (optionally),
155
+ # a width, height, title, and whether or not you want to
156
+ # run in full-screen.
157
+ #
158
+ # This is a little different than Processing where height
159
+ # and width are declared inside the setup method instead.
160
+ def initialize(options = {})
161
+ super()
162
+ $app = App.current = self
163
+ set_sketch_path unless online?
164
+ make_accessible_to_the_browser
165
+ options = {
166
+ :width => 400,
167
+ :height => 400,
168
+ :title => "",
169
+ :full_screen => false
170
+ }.merge(options)
171
+ @width, @height, @title = options[:width], options[:height], options[:title]
172
+ @render_mode = P2D
173
+ determine_how_to_display options
174
+ end
175
+
176
+
177
+ # Provide a loggable string to represent this sketch.
178
+ def inspect
179
+ "#<Processing::App:#{self.class}:#{@title}>"
180
+ end
181
+
182
+
183
+ # By default, your sketch path is the folder that your sketch is in.
184
+ # If you'd like to do something fancy, feel free.
185
+ def set_sketch_path(path=nil)
186
+ field = self.java_class.declared_field('sketchPath')
187
+ field.set_value(Java.ruby_to_java(self), path || File.dirname(SKETCH_PATH))
188
+ end
189
+
190
+
191
+ # There's just so many functions in Processing,
192
+ # Here's a convenient way to look for them.
193
+ def find_method(method_name)
194
+ reg = Regexp.new("#{method_name}", true)
195
+ self.methods.sort.select {|meth| reg.match(meth)}
196
+ end
197
+
198
+
199
+ # Specify what rendering Processing should use.
200
+ def render_mode(mode_const)
201
+ @render_mode = mode_const
202
+ size(@width, @height, @render_mode)
203
+ end
204
+
205
+
206
+ # Nice block method to draw to a buffer.
207
+ # You can optionally pass it a width, a height, and a renderer.
208
+ # Takes care of starting and ending the draw for you.
209
+ def buffer(buf_width=width, buf_height=height, renderer=@render_mode)
210
+ buf = create_graphics(buf_width, buf_height, renderer)
211
+ buf.begin_draw
212
+ yield buf
213
+ buf.end_draw
214
+ buf
215
+ end
216
+
217
+
218
+ # A nice method to run a given block for a grid.
219
+ # Lifted from action_coding/Nodebox.
220
+ def grid(cols, rows, col_size=1, row_size=1)
221
+ (0..cols*rows).map do |i|
222
+ x = col_size * (i % cols)
223
+ y = row_size * i.div(cols)
224
+ yield x, y
225
+ end
226
+ end
227
+
228
+
229
+ # Fix java conversion problems getting the last key
230
+ def key
231
+ field = java_class.declared_field 'key'
232
+ app = Java.ruby_to_java self
233
+ field.value app
234
+ end
235
+
236
+
237
+ # From ROP. Turns a color hash-string into hexadecimal, for Processing.
238
+ def hex(value)
239
+ value[1..-1].hex + 0xff000000
240
+ end
241
+
242
+
243
+ # Fields that should be made accessible as under_scored.
244
+ def mouse_x; mouseX; end
245
+ def mouse_y; mouseY; end
246
+ def pmouse_x; pmouseX; end
247
+ def pmouse_y; pmouseY; end
248
+ def frame_count; frameCount; end
249
+ def mouse_button; mouseButton; end
250
+ def key_code; keyCode; end
251
+
252
+
253
+ # Is the mouse pressed for this frame?
254
+ def mouse_pressed?
255
+ Java.java_to_primitive(java_class.field("mousePressed").value(java_object))
256
+ end
257
+
258
+
259
+ # Is a key pressed for this frame?
260
+ def key_pressed?
261
+ Java.java_to_primitive(java_class.field("keyPressed").value(java_object))
262
+ end
263
+
264
+
265
+ # lerp_color takes three or four arguments, in Java that's two
266
+ # different methods, one regular and one static, so:
267
+ def lerp_color(*args)
268
+ args.length > 3 ? self.class.lerp_color(*args) : super(*args)
269
+ end
270
+
271
+
272
+ # Cleanly close and shutter a running sketch.
273
+ def close
274
+ Processing::App.current = nil
275
+ control_panel.remove if respond_to?(:control_panel) && !online?
276
+ container = (@frame || JRUBY_APPLET)
277
+ container.remove(self)
278
+ self.destroy
279
+ container.dispose
280
+ end
281
+
282
+
283
+ def quit
284
+ exit
285
+ end
286
+
287
+
288
+ private
289
+
290
+ # Tests to see which display method should run.
291
+ def determine_how_to_display(options)
292
+ if online? # Then display it in an applet.
293
+ display_in_an_applet
294
+ elsif options[:full_screen] # Then display it fullscreen.
295
+ graphics_env = java.awt.GraphicsEnvironment.get_local_graphics_environment.get_default_screen_device
296
+ graphics_env.is_full_screen_supported ? display_full_screen(graphics_env) : display_in_a_window
297
+ else # Then display it in a window.
298
+ display_in_a_window
299
+ end
300
+ end
301
+
302
+
303
+ def display_full_screen(graphics_env)
304
+ @frame = java.awt.Frame.new
305
+ mode = graphics_env.display_mode
306
+ @width, @height = mode.get_width, mode.get_height
307
+ gc = graphics_env.get_default_configuration
308
+ @frame.set_undecorated true
309
+ @frame.set_background java.awt.Color.black
310
+ @frame.set_layout java.awt.BorderLayout.new
311
+ @frame.add(self, java.awt.BorderLayout::CENTER)
312
+ @frame.pack
313
+ graphics_env.set_full_screen_window @frame
314
+ @frame.set_location(0, 0)
315
+ @frame.show
316
+ self.init
317
+ self.request_focus
318
+ end
319
+
320
+
321
+ def display_in_a_window
322
+ @frame = JFrame.new(@title)
323
+ @frame.add(self)
324
+ @frame.setSize(@width, @height + 22)
325
+ @frame.setDefaultCloseOperation(JFrame::EXIT_ON_CLOSE)
326
+ @frame.setResizable(false)
327
+ @frame.show
328
+ self.init
329
+ end
330
+
331
+
332
+ def display_in_an_applet
333
+ JRUBY_APPLET.set_size(@width, @height)
334
+ JRUBY_APPLET.background_color = nil
335
+ JRUBY_APPLET.double_buffered = false
336
+ JRUBY_APPLET.add self
337
+ JRUBY_APPLET.validate
338
+ # Add the callbacks to peacefully expire.
339
+ JRUBY_APPLET.on_stop { self.stop }
340
+ JRUBY_APPLET.on_destroy { self.destroy }
341
+ self.init
342
+ end
343
+
344
+
345
+ # When the net library is included, we make the Ruby interpreter
346
+ # accessible to javascript as the 'ruby' variable. From javascript,
347
+ # you can call evalScriptlet() to run code against the sketch.
348
+ def make_accessible_to_the_browser
349
+ return unless library_loaded?('net') && online?
350
+ field = java.lang.Class.for_name("org.jruby.JRubyApplet").get_declared_field("runtime")
351
+ field.set_accessible true
352
+ ruby = field.get(JRUBY_APPLET)
353
+ window = Java::netscape.javascript.JSObject.get_window(JRUBY_APPLET)
354
+ window.set_member('ruby', ruby)
355
+ end
356
+
357
+ end
358
+ end