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,75 @@
1
+ module Processing
2
+
3
+ # A utility class to export Ruby-Processing sketches as applets
4
+ # that can be viewed online.
5
+ class AppletExporter < BaseExporter
6
+
7
+ USAGE = <<-EOS
8
+
9
+ The applet generator will generate a web-ready applet for you.
10
+ Usage: script/applet <path_to_sketch>
11
+ Example: script/applet samples/jwishy.rb
12
+
13
+ EOS
14
+
15
+ def export!(sketch)
16
+ # Check to make sure that the main file exists
17
+ @main_file_path, @main_file, @main_folder = *get_main_file(sketch)
18
+ usage(@main_file_path && File.exists?(@main_file_path))
19
+
20
+ extract_information
21
+
22
+ compute_destination_name
23
+
24
+ wipe_and_recreate_destination
25
+
26
+ copy_over_necessary_files
27
+
28
+ process_opengl_replacements
29
+
30
+ calculate_substitutions
31
+
32
+ render_erb_in_path_with_binding(@dest, binding, :delete => true)
33
+ end
34
+
35
+ def compute_destination_name
36
+ @dest = "#{@main_file.sub(".rb", "")}"
37
+ end
38
+
39
+ def copy_over_necessary_files
40
+ @necessary_files = [@main_file_path]
41
+ @necessary_files += Dir["#{RP5_ROOT}/lib/{*,**}"]
42
+ @necessary_files += @real_requires
43
+ @necessary_files << "#{@main_folder}/data" if File.exists?("#{@main_folder}/data")
44
+ @necessary_files += Dir["#{RP5_ROOT}/lib/templates/applet/{*,**}"]
45
+ @necessary_files += Dir.glob("library/{#{@libraries.join(",")}}") unless @libraries.empty?
46
+ @necessary_files.uniq!
47
+ cp_r(@necessary_files, @dest)
48
+ cp_r(@libraries, File.join(@dest, "library")) unless @libraries.empty?
49
+ end
50
+
51
+ def process_opengl_replacements
52
+ @starting_class = @opengl ? "com.sun.opengl.util.JOGLAppletLauncher" : "org.jruby.JRubyApplet"
53
+ return unless @opengl
54
+ opengl_files = Dir["#{@dest}/library/opengl/*.jar"]
55
+ opengl_files += Dir["#{@dest}/library/opengl/library/*.jar"]
56
+ move(opengl_files, @dest)
57
+ opengl_dir = "#{@dest}/library/opengl"
58
+ remove_entry_secure(opengl_dir) if File.exists?(opengl_dir)
59
+ @necessary_files.map! {|file| file.match(/^opengl/) ? File.basename(file) : file }
60
+ end
61
+
62
+ def calculate_substitutions
63
+ file_list = Dir.glob(@dest + "{/**/*.{rb,jar},/data/*.*}").map {|f| f.sub(@dest+"/","")}
64
+ @width_plus_14 = (@width.to_i + 14).to_s
65
+ @file_list = file_list.join(",")
66
+ end
67
+
68
+ def usage(predicate)
69
+ return if predicate
70
+ puts USAGE
71
+ exit
72
+ end
73
+
74
+ end
75
+ end
@@ -0,0 +1,87 @@
1
+ module Processing
2
+
3
+ # A utility class to export Ruby-Processing sketches as
4
+ # Mac/Win/Nix Applications.
5
+ class ApplicationExporter < BaseExporter
6
+
7
+ USAGE = <<-EOS
8
+
9
+ The application exporter will generate a Mac application for you.
10
+ Usage: script/application <path_to_sketch>
11
+ Example: script/applet samples/jwishy.rb
12
+
13
+ EOS
14
+
15
+ def export!(sketch)
16
+ # Check to make sure that the main file exists
17
+ @main_file_path, @main_file, @main_folder = *get_main_file(sketch)
18
+ usage( @main_file_path && File.exists?(@main_file_path) )
19
+
20
+ extract_information
21
+
22
+ compute_destination_name
23
+
24
+ wipe_and_recreate_destination
25
+
26
+ copy_over_necessary_files
27
+
28
+ calculate_substitutions
29
+
30
+ create_executables
31
+
32
+ symlink_library_into_place
33
+ end
34
+
35
+ def compute_destination_name
36
+ @dest = "#{@title}.app"
37
+ end
38
+
39
+ def copy_over_necessary_files
40
+ @prefix = "lib"
41
+ cp_r(Dir["#{RP5_ROOT}/lib/templates/application/{*,**}"], @dest)
42
+ @necessary_files = [@main_file_path]
43
+ @necessary_files += Dir["#{RP5_ROOT}/lib/{*,**}"]
44
+ @necessary_files += @real_requires
45
+ @necessary_files << "#{@main_folder}/data" if File.exists?("#{@main_folder}/data")
46
+ @necessary_files.uniq!
47
+ cp_r(@necessary_files, File.join(@dest, @prefix))
48
+ cp_r(@libraries, File.join(@dest, @prefix, "library")) unless @libraries.empty?
49
+ # Then move the icon
50
+ potential_icon = Dir.glob(File.join(@dest, @prefix, "data/*.icns"))[0]
51
+ move(potential_icon, File.join(@dest, "Contents/Resources/sketch.icns"), :force => true ) if potential_icon
52
+ end
53
+
54
+ def calculate_substitutions
55
+ file_list = Dir.glob(@dest + "{/**/*.{rb,jar},/data/*.*}").map {|f| f.sub(@dest + "/", "")}
56
+ @class_path = file_list.map {|f| "$JAVAROOT/" + f.sub(@prefix+"/", "") }.join(":")
57
+ @linux_class_path = file_list.map{|f| f.sub(@prefix+"/", "")}.join(":")
58
+ @windows_class_path = file_list.map{|f| f.sub(@prefix+"/", "")}.join(",")
59
+ end
60
+
61
+ def create_executables
62
+ render_erb_in_path_with_binding(@dest, binding, :delete => true)
63
+ rm Dir.glob(@dest + "/**/*.java")
64
+ runnable = @dest + "/" + File.basename(@main_file, ".rb")
65
+ move @dest + "/run", runnable
66
+ move @dest + "/run.exe", "#{runnable}.exe"
67
+ chmod 0755, runnable
68
+ chmod 0755, "#{runnable}.exe"
69
+ end
70
+
71
+ def symlink_library_into_place
72
+ cd @dest + "/Contents/Resources"
73
+ # Poor ol' windows can't symlink.
74
+ # TODO...
75
+ win = RUBY_PLATFORM.match(/mswin/)
76
+ puts "\n[warning] Applications exported from Windows won't run on Macs...\n" if win
77
+ ln_s('../../lib', 'Java') unless win
78
+ end
79
+
80
+ def usage(predicate)
81
+ return if predicate
82
+ puts USAGE
83
+ exit
84
+ end
85
+
86
+ end
87
+ end
@@ -0,0 +1,133 @@
1
+ require 'fileutils'
2
+ require 'erb'
3
+
4
+ module Processing
5
+
6
+ # This base exporter implements some of the common
7
+ # code-munging needed to generate apps and applets.
8
+ class BaseExporter
9
+ include FileUtils
10
+
11
+ DEFAULT_TITLE = "Ruby-Processing Sketch"
12
+ DEFAULT_DIMENSIONS = {'width' => '500', 'height' => '500'}
13
+ DEFAULT_DESCRIPTION = ''
14
+
15
+ # Returns the filepath, basename, and directory name of the sketch.
16
+ def get_main_file(file)
17
+ return file, File.basename(file), File.dirname(file)
18
+ end
19
+
20
+ # Centralized method to read the source of the sketch and extract
21
+ # all the juicy details.
22
+ def extract_information
23
+ # Extract information from main file
24
+ @info = {}
25
+ @info[:source_code] = source = read_source_code
26
+ @info[:class_name] = extract_class_name(source)
27
+ @info[:title] = extract_title(source)
28
+ @info[:width] = extract_dimension(source, 'width')
29
+ @info[:height] = extract_dimension(source, 'height')
30
+ @info[:description] = extract_description(source)
31
+ @info[:libraries] = extract_libraries(source)
32
+ @info[:real_requires] = extract_real_requires(source)
33
+ hash_to_ivars @info
34
+ @info
35
+ end
36
+
37
+ # Searches the source for a class name.
38
+ def extract_class_name(source)
39
+ match = source.match(/(\w+)\s*<\s*Processing::App/)
40
+ match ? match[1] : nil
41
+ end
42
+
43
+ # Searches the source for a title.
44
+ def extract_title(source)
45
+ match = source.match(/#{@info[:class_name]}\.new.*?:title\s=>\s["'](.+)["']/m)
46
+ match ? match[1] : DEFAULT_TITLE
47
+ end
48
+
49
+ # Searches the source for the width and height of the sketch.
50
+ def extract_dimension(source, dimension)
51
+ match = source.match(/#{@info[:class_name]}\.new.*?:#{dimension}\s=>\s(\d+)/m)
52
+ match ? match[1] : DEFAULT_DIMENSIONS[dimension]
53
+ end
54
+
55
+ # Searches the source for a description of the sketch.
56
+ def extract_description(source)
57
+ match = source.match(/# Description:(.*?)\n[^#]/m)
58
+ match ? match[1].gsub!(/\n(\s*)?#/, "") : DEFAULT_DESCRIPTION
59
+ end
60
+
61
+ # Searches the source any libraries that have been loaded.
62
+ def extract_libraries(source)
63
+ libs = []
64
+ code = source.dup
65
+ loop do
66
+ matchdata = code.match(/load_\w+_library.+?["':](\S+?)["'\s]/)
67
+ break unless matchdata
68
+ match = matchdata[1]
69
+ @opengl = true if match.match(/opengl/i)
70
+ local_path = "#{local_dir}/library/#{match}"
71
+ rp5_path = "#{RP5_ROOT}/library/#{match}"
72
+ File.exists?(local_path) ? libs << local_path :
73
+ (libs << rp5_path if File.exists?(rp5_path))
74
+ code = matchdata.post_match
75
+ end
76
+ libs
77
+ end
78
+
79
+ # Looks for all of the codes require or load commands, checks
80
+ # to see if the file exists (that it's not a gem, or a standard lib)
81
+ # and hands you back all the real ones.
82
+ def extract_real_requires(source)
83
+ code = source.dup
84
+ requirements = []
85
+ partial_paths = []
86
+ loop do
87
+ matchdata = code.match(/^.*\b(require|load)\b.*$/)
88
+ break unless matchdata
89
+ line = matchdata[0].gsub('__FILE__', "'#{@main_file_path}'")
90
+ line = line.gsub(/\b(require|load)\b/, 'partial_paths << ')
91
+ eval(line)
92
+ requirements += Dir["{#{local_dir}/,}{#{partial_paths.join(',')}}.{rb,jar}"]
93
+ code = matchdata.post_match
94
+ end
95
+ return requirements
96
+ end
97
+
98
+
99
+ protected
100
+
101
+ def read_source_code
102
+ File.read(@main_file_path)
103
+ end
104
+
105
+ def local_dir
106
+ File.dirname(@main_file_path)
107
+ end
108
+
109
+ def hash_to_ivars(hash)
110
+ hash.each{|k,v| instance_variable_set("@" + k.to_s, v) }
111
+ end
112
+
113
+ def wipe_and_recreate_destination
114
+ remove_entry_secure @dest if File.exists?(@dest)
115
+ mkdir_p @dest
116
+ end
117
+
118
+ def render_erb_in_path_with_binding(path, some_binding, opts={})
119
+ erbs = Dir.glob(path + "/**/*.erb")
120
+ erbs.each do |erb|
121
+ string = File.open(erb) {|f| f.read }
122
+ rendered = render_erb_from_string_with_binding(string, some_binding)
123
+ File.open(erb.sub(".erb", ""), "w") {|f| f.print rendered }
124
+ rm erb if opts[:delete]
125
+ end
126
+ end
127
+
128
+ def render_erb_from_string_with_binding(erb, some_binding)
129
+ rendered = ERB.new(erb, nil, "<>", "rendered").result(some_binding)
130
+ end
131
+
132
+ end
133
+ end
@@ -0,0 +1,46 @@
1
+ module Processing
2
+
3
+ # This class creates blank sketches, with the boilerplate filled in.
4
+ class Creator < BaseExporter
5
+
6
+ # Create a blank sketch, given a path.
7
+ def create!(path, args)
8
+ usage path
9
+ main_file = File.basename(path, ".rb")
10
+ # Check to make sure that the main file exists
11
+ already_exists = File.exists?(path) || File.exists?("#{File.dirname(path)}/#{main_file.underscore}.rb")
12
+ puts "That sketch already exists." and exit if already_exists
13
+
14
+ # Get the substitutions
15
+ @name = main_file.camelize
16
+ @file_name = main_file.underscore
17
+ @title = main_file.titleize
18
+ @width = args[0] || "500"
19
+ @height = args[1] || "500"
20
+
21
+ # Make the file
22
+ dir = File.dirname path
23
+ mkdir_p dir
24
+ template = File.new("#{RP5_ROOT}/lib/templates/create/blank_sketch.rb.erb")
25
+ rendered = render_erb_from_string_with_binding(template.read, binding)
26
+ File.open(File.join(dir, "#{@file_name}.rb"), "w") do |file|
27
+ file.print rendered
28
+ end
29
+ end
30
+
31
+ # Show the help/usage message for create.
32
+ def usage(predicate)
33
+ unless predicate
34
+ puts <<-USAGE
35
+
36
+ Usage: script/generate <sketch_to_generate> <width> <height>
37
+ Width and Height are optional.
38
+
39
+ Example: script/generate fancy_drawing/app 800 600
40
+
41
+ USAGE
42
+ exit
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,27 @@
1
+ class String #:nodoc:
2
+
3
+ def titleize
4
+ self.underscore.humanize.gsub(/\b([a-z])/) { $1.capitalize }
5
+ end
6
+
7
+ def humanize()
8
+ self.gsub(/_id$/, "").gsub(/_/, " ").capitalize
9
+ end
10
+
11
+ def camelize(first_letter_in_uppercase = true)
12
+ if first_letter_in_uppercase
13
+ self.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
14
+ else
15
+ self.first + self.camelize[1..-1]
16
+ end
17
+ end
18
+
19
+ def underscore
20
+ self.gsub(/::/, '/').
21
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
22
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
23
+ tr("-", "_").
24
+ downcase
25
+ end
26
+
27
+ end
@@ -0,0 +1,143 @@
1
+ require 'ostruct'
2
+ require 'fileutils'
3
+
4
+ module Processing
5
+
6
+ # Utility class to handle the different commands that the 'rp5' command
7
+ # offers. Able to run, watch, live, create, app, applet, and unpack
8
+ class Runner
9
+
10
+ HELP_MESSAGE = <<-EOS
11
+
12
+ Ruby-Processing is a little shim between Processing and JRuby that helps
13
+ you create sketches of code art.
14
+
15
+ Usage:
16
+ rp5 [run | watch | live | create | app | applet | unpack] path/to/sketch
17
+
18
+ Examples:
19
+ rp5 unpack samples
20
+ rp5 run samples/jwishy.rb
21
+ rp5 create some_new_sketch 640 480
22
+ rp5 watch some_new_sketch.rb
23
+ rp5 applet some_new_sketch.rb
24
+
25
+ Further information:
26
+ http://wiki.github.com/jashkenas/ruby-processing
27
+
28
+ EOS
29
+
30
+ # Start running a ruby-processing sketch from the passed-in arguments
31
+ def self.execute
32
+ runner = new
33
+ runner.parse_options(ARGV)
34
+ runner.execute!
35
+ end
36
+
37
+ # Dispatch central.
38
+ def execute!
39
+ case @options.action
40
+ when 'run' : run(@options.path)
41
+ when 'watch' : watch(@options.path)
42
+ when 'create' : create(@options.path, @options.args)
43
+ when 'live' : live(@options.path)
44
+ when 'app' : app(@options.path)
45
+ when 'applet' : applet(@options.path)
46
+ when 'unpack' : unpack(@options.path)
47
+ when /-v/ : show_version
48
+ when /-h/ : show_help
49
+ else show_help
50
+ end
51
+ end
52
+
53
+ # Parse the command-line options. Keep it simple.
54
+ def parse_options(args)
55
+ @options = OpenStruct.new
56
+ @options.action = args[0] || nil
57
+ @options.path = args[1] || File.basename(Dir.pwd + '.rb')
58
+ @options.args = args[2..-1] || []
59
+ end
60
+
61
+ # Create a fresh Ruby-Processing sketch, with the necessary
62
+ # boilerplate filled out.
63
+ def create(sketch, args)
64
+ Processing::Creator.new.create!(sketch, args)
65
+ end
66
+
67
+ # Just simply run a ruby-processing sketch.
68
+ def run(sketch)
69
+ ensure_exists(sketch)
70
+ spin_up('run.rb', sketch)
71
+ end
72
+
73
+ # Run a sketch, keeping an eye on it's file, and reloading
74
+ # whenever it changes.
75
+ def watch(sketch)
76
+ ensure_exists(sketch)
77
+ spin_up('watch.rb', sketch)
78
+ end
79
+
80
+ # Run a sketch, opening its guts to IRB, letting you play with it.
81
+ def live(sketch)
82
+ ensure_exists(sketch)
83
+ spin_up('live.rb', sketch)
84
+ end
85
+
86
+ # Generate a cross-platform application of a given Ruby-Processing sketch.
87
+ def app(sketch)
88
+ Processing::ApplicationExporter.new.export!(sketch)
89
+ end
90
+
91
+ # Generate an applet and HTML page for a given sketch.
92
+ def applet(sketch)
93
+ Processing::AppletExporter.new.export!(sketch)
94
+ end
95
+
96
+ # Install the included samples to a given path, where you can run and
97
+ # alter them to your heart's content.
98
+ def unpack(dir)
99
+ require 'fileutils'
100
+ usage = "Usage: rp5 unpack [samples | library]"
101
+ puts usage and return unless dir.match(/\A(samples|library)\Z/)
102
+ FileUtils.cp_r("#{RP5_ROOT}/#{dir}", "#{Dir.pwd}/#{dir}")
103
+ end
104
+
105
+ # Display the current version of Ruby-Processing.
106
+ def show_version
107
+ puts "Ruby-Processing version #{Processing.version}"
108
+ end
109
+
110
+ # Show the standard help/usage message.
111
+ def show_help
112
+ puts HELP_MESSAGE
113
+ end
114
+
115
+
116
+ private
117
+
118
+ # Trade in this Ruby instance for a JRuby instance, loading in a
119
+ # starter script and passing it some arguments.
120
+ def spin_up(starter_script, args)
121
+ runner = "#{RP5_ROOT}/lib/ruby-processing/runners/#{starter_script}"
122
+ command = "java -cp #{jruby_complete} #{dock_icon} org.jruby.Main #{runner} #{args}"
123
+ exec(command)
124
+ # exec replaces the Ruby process with the JRuby one.
125
+ end
126
+
127
+ def ensure_exists(sketch)
128
+ puts "Couldn't find: #{sketch}" and exit unless File.exists?(sketch)
129
+ end
130
+
131
+ def jruby_complete
132
+ File.join(RP5_ROOT, 'lib/core/jruby-complete.jar')
133
+ end
134
+
135
+ # On the Mac, we can display a fat, shiny ruby in the Dock.
136
+ def dock_icon
137
+ mac = RUBY_PLATFORM.match(/darwin/i)
138
+ mac ? "-Xdock:name=Ruby-Processing -Xdock:icon=#{RP5_ROOT}/lib/templates/application/Contents/Resources/sketch.icns" : ""
139
+ end
140
+
141
+ end # class Runner
142
+
143
+ end # module Processing