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 @@
1
+ 2.0.1
Binary file
@@ -0,0 +1,13 @@
1
+ # If you want to support more platforms, see the jogl.dev.java.net to get the
2
+ # natives libraries for the platform in question (i.e. solaris). Then, add it
3
+ # them to the applet line for export. For applications, you'll have to make the
4
+ # changes by hand, i.e. use the linux version of the export, and modify its
5
+ # contents to include the necessary files for your platform.
6
+
7
+ application.macosx = opengl.jar, jogl.jar, libjogl.jnilib, libjogl_awt.jnilib, libjogl_cg.jnilib, gluegen-rt.jar, libgluegen-rt.jnilib
8
+
9
+ application.windows = opengl.jar, jogl.jar, jogl.dll, jogl_awt.dll, jogl_cg.dll, gluegen-rt.jar, gluegen-rt.dll
10
+
11
+ application.linux = opengl.jar, jogl.jar, gluegen-rt.jar, libjogl.so, libjogl_awt.so, libjogl_cg.so, libgluegen-rt.so
12
+
13
+ applet = opengl.jar, jogl.jar, jogl.jar.pack.gz, jogl-natives-linux-i586.jar, jogl-natives-linux-amd64.jar, jogl-natives-macosx-ppc.jar, jogl-natives-macosx-universal.jar, jogl-natives-windows-i586.jar, jogl-natives-windows-amd64.jar, gluegen-rt.jar, gluegen-rt.jar.pack.gz, gluegen-rt-natives-linux-amd64.jar, gluegen-rt-natives-windows-amd64.jar, gluegen-rt-natives-linux-i586.jar, gluegen-rt-natives-windows-i586.jar, gluegen-rt-natives-macosx-ppc.jar, gluegen-rt-natives-macosx-universal.jar
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,9 @@
1
+ The majority of the work in this library is done by iText.
2
+ http://www.lowagie.com/iText/
3
+
4
+ The version bundled in this release is 2.1.2u.
5
+
6
+ The files in the library must be named itext.jar (not iText-2.1.2u.jar)
7
+ because they're specifically included on the classpath as part of the
8
+ build/platform/make.sh scripts.
9
+
Binary file
@@ -0,0 +1,3 @@
1
+ application.macosx = serial.jar, RXTXcomm.jar, librxtxSerial.jnilib
2
+ application.windows = serial.jar, RXTXcomm.jar, rxtxSerial.dll
3
+ application.linux = serial.jar, RXTXcomm.jar, librxtxSerial.so
Binary file
Binary file
@@ -0,0 +1,47 @@
1
+ # From the Processing Examples
2
+ # -- omygawshkenas
3
+
4
+ require 'ruby-processing'
5
+
6
+ class Animator < Processing::App
7
+ FRAME_COUNT = 12
8
+
9
+ def setup
10
+ @frames = []
11
+ @last_time = 0
12
+ @current_frame = 0
13
+ @draw = false
14
+ @back_color = 204
15
+ stroke_weight 4
16
+ smooth
17
+ background @back_color
18
+ FRAME_COUNT.times { @frames << get() }
19
+ end
20
+
21
+ def draw
22
+ time = millis()
23
+ if time > @last_time + 100
24
+ next_frame
25
+ @last_time = time
26
+ end
27
+ line(pmouse_x, pmouse_y, mouse_x, mouse_y) if @draw
28
+ end
29
+
30
+ def mouse_pressed; @draw = true; end
31
+ def mouse_released; @draw = false; end
32
+
33
+ def key_pressed
34
+ background @back_color
35
+ @frames.size.times {|i| @frames[i] = get()}
36
+ end
37
+
38
+ def next_frame
39
+ @frames[@current_frame] = get()
40
+ @current_frame += 1
41
+ @current_frame = 0 if @current_frame >= @frames.size
42
+ image(@frames[@current_frame], 0, 0)
43
+ end
44
+
45
+ end
46
+
47
+ Animator.new :title => "Animator", :width => 350, :height => 350
@@ -0,0 +1,213 @@
1
+ # Based on http://processing.org/learning/topics/circlecollision.html
2
+ # by Joe Holt
3
+
4
+ require 'ruby-processing'
5
+
6
+ class Vect2D
7
+ attr_accessor :vx, :vy
8
+ def initialize(vx = 0.0, vy = 0.0)
9
+ @vx = vx
10
+ @vy = vy
11
+ end
12
+ end
13
+
14
+
15
+ class Ball
16
+ attr_accessor :x, :y, :r, :m, :vec
17
+ def initialize(r = 0.0, vec = nil, x = 0.0, y = 0.0)
18
+ @x = x
19
+ @y = y
20
+ @r = r
21
+ @m = r*0.1
22
+ @vec = vec
23
+ end
24
+
25
+ def draw
26
+ r = @r * 2
27
+ P.ellipse @x, @y, r, r
28
+ @px = @x
29
+ @py = @y
30
+ end
31
+
32
+ def erase
33
+ r = @r * 2
34
+ P.rect @px, @py, r, r
35
+ end
36
+ end
37
+
38
+
39
+ class Sketch < Processing::App
40
+
41
+ def setup
42
+ smooth
43
+ noStroke
44
+ frameRate 30
45
+ rectMode RADIUS
46
+
47
+ @balls = []
48
+ 5.times { @balls << Ball.new(10, Vect2D.new(2.15, -1.35), *emptySpace(15)) }
49
+ 2.times { @balls << Ball.new(40, Vect2D.new(-1.65, 0.42), *emptySpace(45)) }
50
+
51
+ @frame_time = nil
52
+ @frame_count = 0
53
+ end
54
+
55
+
56
+ def draw
57
+ t = Time.now
58
+ if @frame_time
59
+ fps = 1.0 / (t - @frame_time)
60
+ end
61
+ @frame_time = t
62
+ @frame_count += 1
63
+
64
+ # erase previous screen
65
+ if @frame_count == 1
66
+ background 51
67
+ else
68
+ fill 51
69
+ @balls.each { |ball| ball.erase }
70
+ end
71
+
72
+ # move the balls
73
+ fill 240
74
+ @balls.each do |ball|
75
+ ball.x += ball.vec.vx
76
+ ball.y += ball.vec.vy
77
+ ball.draw
78
+ checkBoundaryCollision ball
79
+ end
80
+ checkObjectCollisions
81
+ 1 * 20
82
+ end
83
+
84
+
85
+ def emptySpace(r)
86
+ x = y = nil
87
+ while !x || !emptySpace?(x, y, r) do
88
+ x = rand(width)
89
+ y = rand(height)
90
+ end
91
+ return x, y
92
+ end
93
+
94
+
95
+ def emptySpace?(x, y, r)
96
+ @balls.each do |ball|
97
+ vx = x - ball.x
98
+ vy = y - ball.y
99
+ mag = sqrt(vx * vx + vy * vy)
100
+ return false if mag < r + ball.r
101
+ end
102
+ return true
103
+ end
104
+
105
+
106
+ def checkObjectCollisions
107
+
108
+ (0...(@balls.length)).each do |ia|
109
+ ((ia+1)...(@balls.length)).each do |ib|
110
+
111
+ ba = @balls[ia]
112
+ bb = @balls[ib]
113
+
114
+ # get distances between the balls components
115
+ bVect = Vect2D.new
116
+ bVect.vx = bb.x - ba.x
117
+ bVect.vy = bb.y - ba.y
118
+
119
+ # calculate magnitude of the vector separating the balls
120
+ bVectMag = sqrt(bVect.vx * bVect.vx + bVect.vy * bVect.vy)
121
+ next if bVectMag >= ba.r + bb.r
122
+ # get angle of bVect
123
+ theta = atan2(bVect.vy, bVect.vx)
124
+ # precalculate trig values
125
+ sine = sin(theta)
126
+ cosine = cos(theta)
127
+
128
+ # bTemp will hold rotated ball positions. You just
129
+ # need to worry about bTemp[1] position
130
+ bTemp = [Ball.new, Ball.new]
131
+ # bb's position is relative to ba's
132
+ # so you can use the vector between them (bVect) as the
133
+ # reference point in the rotation expressions.
134
+ # bTemp[0].x and bTemp[0].y will initialize
135
+ # automatically to 0.0, which is what you want
136
+ # since bb will rotate around ba
137
+ bTemp[1].x = cosine * bVect.vx + sine * bVect.vy
138
+ bTemp[1].y = cosine * bVect.vy - sine * bVect.vx
139
+
140
+ # rotate Temporary velocities
141
+ vTemp = [Vect2D.new, Vect2D.new]
142
+ vTemp[0].vx = cosine * ba.vec.vx + sine * ba.vec.vy
143
+ vTemp[0].vy = cosine * ba.vec.vy - sine * ba.vec.vx
144
+ vTemp[1].vx = cosine * bb.vec.vx + sine * bb.vec.vy
145
+ vTemp[1].vy = cosine * bb.vec.vy - sine * bb.vec.vx
146
+
147
+ # Now that velocities are rotated, you can use 1D
148
+ # conservation of momentum equations to calculate
149
+ # the final velocity along the x-axis.
150
+ vFinal = [Vect2D.new, Vect2D.new]
151
+ # final rotated velocity for ba
152
+ vFinal[0].vx = ((ba.m - bb.m) * vTemp[0].vx + 2 * bb.m *
153
+ vTemp[1].vx) / (ba.m + bb.m)
154
+ vFinal[0].vy = vTemp[0].vy
155
+ # final rotated velocity for ba
156
+ vFinal[1].vx = ((bb.m - ba.m) * vTemp[1].vx + 2 * ba.m *
157
+ vTemp[0].vx) / (ba.m + bb.m)
158
+ vFinal[1].vy = vTemp[1].vy
159
+
160
+ # hack to avoid clumping
161
+ bTemp[0].x += vFinal[0].vx
162
+ bTemp[1].x += vFinal[1].vx
163
+
164
+ # Rotate ball positions and velocities back
165
+ # Reverse signs in trig expressions to rotate
166
+ # in the opposite direction
167
+ # rotate balls
168
+ bFinal = [Ball.new, Ball.new]
169
+ bFinal[0].x = cosine * bTemp[0].x - sine * bTemp[0].y
170
+ bFinal[0].y = cosine * bTemp[0].y + sine * bTemp[0].x
171
+ bFinal[1].x = cosine * bTemp[1].x - sine * bTemp[1].y
172
+ bFinal[1].y = cosine * bTemp[1].y + sine * bTemp[1].x
173
+
174
+ # update balls to screen position
175
+ bb.x = ba.x + bFinal[1].x
176
+ bb.y = ba.y + bFinal[1].y
177
+ ba.x = ba.x + bFinal[0].x
178
+ ba.y = ba.y + bFinal[0].y
179
+
180
+ # update velocities
181
+ ba.vec.vx = cosine * vFinal[0].vx - sine * vFinal[0].vy
182
+ ba.vec.vy = cosine * vFinal[0].vy + sine * vFinal[0].vx
183
+ bb.vec.vx = cosine * vFinal[1].vx - sine * vFinal[1].vy
184
+ bb.vec.vy = cosine * vFinal[1].vy + sine * vFinal[1].vx
185
+ end
186
+ end
187
+
188
+ end
189
+
190
+
191
+ def checkBoundaryCollision(ball)
192
+
193
+ if ball.x > width-ball.r
194
+ ball.x = width-ball.r
195
+ ball.vec.vx *= -1
196
+ elsif ball.x < ball.r
197
+ ball.x = ball.r
198
+ ball.vec.vx *= -1
199
+ end
200
+ if ball.y > height-ball.r
201
+ ball.y = height-ball.r
202
+ ball.vec.vy *= -1
203
+ elsif ball.y < ball.r
204
+ ball.y = ball.r
205
+ ball.vec.vy *= -1
206
+ end
207
+
208
+ end
209
+
210
+ end
211
+
212
+
213
+ P = Sketch.new(:width => 400, :height => 400, :title => "CircleCollision2")
data/samples/fern.rb ADDED
@@ -0,0 +1,49 @@
1
+ # The Fern Fractal
2
+ # by Luis Correia
3
+ #
4
+ # port by omygawshkenas
5
+
6
+ require 'ruby-processing'
7
+
8
+ class Fern < Processing::App
9
+
10
+ def setup
11
+ no_loop
12
+ puts "Be patient. This takes about 10 seconds to render."
13
+ end
14
+
15
+ def draw
16
+ background 0
17
+ load_pixels
18
+ x0, y0 = 0.0, 0.0
19
+ x, y, r = 0.0, 0.0, 0.0
20
+ i, j = 0, 0
21
+ max_iterations = 200000
22
+
23
+ max_iterations.times do
24
+ r = rand * 100
25
+ if r <= 1
26
+ x = 0.0
27
+ y = 0.16 * y0
28
+ elsif r <= 7
29
+ x = 0.2 * x0 - 0.26 * y0
30
+ y = 0.23 * x0 + 0.22 * y0
31
+ elsif r <= 14
32
+ x = -0.15 * x0 + 0.28 * y0
33
+ y = 0.26 * x0 + 0.24 * y0
34
+ else
35
+ x = 0.85 * x0 + 0.04 * y0
36
+ y = -0.004 * x0 + 0.85 * y0 + 1.6
37
+ end
38
+
39
+ i = height - (y * 45).to_i
40
+ j = width / 2 + (x * 45).to_i
41
+ pixels[i * height + j] += 2560 if (i >=0 && i < height && j >= 0 && j < width)
42
+ x0, y0 = x, y
43
+ end
44
+
45
+ update_pixels
46
+ end
47
+ end
48
+
49
+ Fern.new :title => "Fern", :width => 500, :height => 500