ruby-processing 1.0.9 → 1.0.10.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. data/CHANGELOG +13 -1
  2. data/bin/rp5 +8 -2
  3. data/lib/core/core.jar +0 -0
  4. data/lib/core/jruby-complete.jar +0 -0
  5. data/lib/ruby-processing.rb +2 -2
  6. data/lib/ruby-processing/app.rb +108 -338
  7. data/lib/ruby-processing/config.rb +6 -0
  8. data/lib/ruby-processing/helper_methods.rb +120 -0
  9. data/lib/ruby-processing/library_loader.rb +140 -0
  10. data/lib/ruby-processing/runner.rb +34 -4
  11. data/lib/ruby-processing/runners/base.rb +10 -11
  12. data/lib/ruby-processing/runners/live.rb +1 -1
  13. data/lib/ruby-processing/runners/run.rb +1 -1
  14. data/lib/ruby-processing/runners/watch.rb +18 -76
  15. data/lib/templates/applet/index.html.erb +8 -9
  16. data/library/control_panel/control_panel.rb +1 -1
  17. data/library/dxf/library/dxf.jar +0 -0
  18. data/library/dxf/library/export.txt +1 -0
  19. data/library/javascript/library/export.txt +3 -1
  20. data/library/minim/library/export.txt +1 -0
  21. data/library/minim/library/jl1.0.jar +0 -0
  22. data/library/minim/library/jsminim.jar +0 -0
  23. data/library/minim/library/minim-spi.jar +0 -0
  24. data/library/minim/library/minim.jar +0 -0
  25. data/library/minim/library/mp3spi1.9.4.jar +0 -0
  26. data/library/minim/library/tritonus_aos.jar +0 -0
  27. data/library/minim/library/tritonus_share.jar +0 -0
  28. data/library/net/library/export.txt +1 -0
  29. data/library/net/library/net.jar +0 -0
  30. data/library/opengl/library/export.txt +7 -10
  31. data/library/opengl/library/gluegen-rt.jar +0 -0
  32. data/library/opengl/library/jogl.jar +0 -0
  33. data/library/opengl/library/{libgluegen-rt.so → linux32/libgluegen-rt.so} +0 -0
  34. data/library/opengl/library/{libjogl.so → linux32/libjogl.so} +0 -0
  35. data/library/opengl/library/{libjogl_awt.so → linux32/libjogl_awt.so} +0 -0
  36. data/library/opengl/library/{libjogl_cg.so → linux32/libjogl_cg.so} +0 -0
  37. data/library/opengl/library/linux64/libgluegen-rt.so +0 -0
  38. data/library/opengl/library/linux64/libjogl.so +0 -0
  39. data/library/opengl/library/linux64/libjogl_awt.so +0 -0
  40. data/library/opengl/library/linux64/libjogl_cg.so +0 -0
  41. data/library/opengl/library/{libgluegen-rt.jnilib → macosx/libgluegen-rt.jnilib} +0 -0
  42. data/library/opengl/library/{libjogl.jnilib → macosx/libjogl.jnilib} +0 -0
  43. data/library/opengl/library/{libjogl_awt.jnilib → macosx/libjogl_awt.jnilib} +0 -0
  44. data/library/opengl/library/{libjogl_cg.jnilib → macosx/libjogl_cg.jnilib} +0 -0
  45. data/library/opengl/library/opengl.jar +0 -0
  46. data/library/opengl/library/{gluegen-rt.dll → windows32/gluegen-rt.dll} +0 -0
  47. data/library/opengl/library/{jogl.dll → windows32/jogl.dll} +0 -0
  48. data/library/opengl/library/{jogl_awt.dll → windows32/jogl_awt.dll} +0 -0
  49. data/library/opengl/library/{jogl_cg.dll → windows32/jogl_cg.dll} +0 -0
  50. data/library/opengl/library/windows64/gluegen-rt.dll +0 -0
  51. data/library/opengl/library/windows64/jogl.dll +0 -0
  52. data/library/opengl/library/windows64/jogl_awt.dll +0 -0
  53. data/library/opengl/library/windows64/jogl_cg.dll +0 -0
  54. data/library/pdf/library/export.txt +1 -0
  55. data/library/pdf/library/itext.jar +0 -0
  56. data/library/pdf/library/pdf.jar +0 -0
  57. data/library/serial/library/RXTXcomm.jar +0 -0
  58. data/library/serial/library/export.txt +1 -3
  59. data/library/serial/library/linux32/librxtxSerial.so +0 -0
  60. data/library/serial/library/linux64/librxtxSerial.so +0 -0
  61. data/library/serial/library/macosx/librxtxSerial.jnilib +0 -0
  62. data/library/serial/library/serial.jar +0 -0
  63. data/library/serial/library/windows32/rxtxSerial.dll +0 -0
  64. data/library/serial/library/windows64/rxtxSerial.dll +0 -0
  65. data/library/video/library/export.txt +1 -0
  66. data/library/video/library/video.jar +0 -0
  67. data/samples/{animator.rb → contributed/animator.rb} +0 -0
  68. data/samples/{bezier_playground.rb → contributed/bezier_playground.rb} +0 -0
  69. data/samples/{circle_collision.rb → contributed/circle_collision.rb} +0 -0
  70. data/samples/contributed/drawolver.rb +182 -0
  71. data/samples/{empathy.rb → contributed/empathy.rb} +7 -7
  72. data/samples/{fern.rb → contributed/fern.rb} +0 -0
  73. data/samples/{flight_patterns.rb → contributed/flight_patterns.rb} +0 -0
  74. data/samples/{full_screen.rb → contributed/full_screen.rb} +0 -0
  75. data/samples/{getting_started.rb → contributed/getting_started.rb} +0 -0
  76. data/samples/{gravity.rb → contributed/gravity.rb} +0 -0
  77. data/samples/{jwishy.rb → contributed/jwishy.rb} +0 -0
  78. data/samples/{orbit.rb → contributed/orbit.rb} +0 -0
  79. data/samples/{pong.rb → contributed/pong.rb} +0 -0
  80. data/samples/{reflection.rb → contributed/reflection.rb} +0 -0
  81. data/samples/{simple_buffer.rb → contributed/simple_buffer.rb} +0 -0
  82. data/samples/{tree.rb → contributed/tree.rb} +0 -0
  83. data/samples/peasy_cam/library/hilbert/hilbert.rb +11 -10
  84. data/samples/processing_app/3D/camera/move_eye.rb +29 -0
  85. data/samples/processing_app/3D/form/brick_tower.rb +11 -11
  86. data/samples/processing_app/3D/form/cubic_grid.rb +51 -0
  87. data/samples/processing_app/3D/form/icosahedra/icosahedra.rb +76 -0
  88. data/samples/processing_app/3D/form/icosahedra/icosahedron.rb +116 -0
  89. data/samples/processing_app/3D/form/icosahedra/shape_3D.rb +25 -0
  90. data/samples/processing_app/3D/form/primitives.rb +42 -0
  91. data/samples/processing_app/3D/form/rgb_cube.rb +88 -0
  92. data/samples/processing_app/3D/form/shape_transform.rb +94 -0
  93. data/samples/processing_app/3D/form/toroid.rb +130 -0
  94. data/samples/processing_app/3D/form/vertices.rb +81 -0
  95. data/samples/processing_app/3D/image/data/eames.jpg +0 -0
  96. data/samples/processing_app/3D/image/data/ystone08.jpg +0 -0
  97. data/samples/processing_app/3D/image/explode.rb +56 -0
  98. data/samples/processing_app/3D/image/extrusion.rb +49 -0
  99. data/samples/processing_app/3D/image/zoom.rb +83 -0
  100. data/samples/processing_app/3D/lights/directional.rb +41 -0
  101. data/samples/processing_app/3D/lights/lights1.rb +39 -0
  102. data/samples/processing_app/3D/lights/lights2.rb +42 -0
  103. data/samples/processing_app/3D/lights/reflection.rb +38 -0
  104. data/samples/processing_app/3D/lights/spot.rb +39 -0
  105. data/samples/processing_app/3D/textures/data/berlin-1.jpg +0 -0
  106. data/samples/processing_app/3D/textures/texture1.rb +41 -0
  107. data/samples/processing_app/3D/textures/texture2.rb +38 -0
  108. data/samples/processing_app/3D/textures/texture3.rb +68 -0
  109. data/samples/processing_app/3D/textures/texture_cube.rb +106 -0
  110. data/samples/processing_app/3D/transform/bird.rb +61 -0
  111. data/samples/processing_app/3D/transform/birds/bird.rb +87 -0
  112. data/samples/processing_app/3D/transform/birds/birds.rb +48 -0
  113. data/samples/processing_app/3D/transform/cubes_in_cube/cube.rb +57 -0
  114. data/samples/processing_app/3D/transform/cubes_in_cube/cubes_in_cube.rb +102 -0
  115. data/samples/processing_app/3D/transform/push_pop_cubes.rb +152 -0
  116. data/samples/processing_app/3D/transform/rotate1.rb +43 -0
  117. data/samples/processing_app/3D/transform/rotate2.rb +45 -0
  118. data/samples/processing_app/3D/typography/data/Univers45.vlw +0 -0
  119. data/samples/processing_app/3D/typography/letter_k.rb +136 -0
  120. data/samples/processing_app/3D/typography/typing.rb +77 -0
  121. data/samples/processing_app/basics/form/triangle_strip.rb +19 -19
  122. data/samples/processing_app/basics/math/distance1.rb +59 -0
  123. data/samples/processing_app/basics/math/distance2.rb +38 -0
  124. data/samples/processing_app/basics/math/double_random.rb +38 -0
  125. data/samples/processing_app/basics/math/graphing_2_d_equation.rb +53 -0
  126. data/samples/processing_app/basics/math/increment_decrement.rb +59 -0
  127. data/samples/processing_app/basics/math/modulo.rb +43 -0
  128. data/samples/processing_app/basics/math/noise_1_d.rb +37 -0
  129. data/samples/processing_app/basics/math/noise_2_d.rb +47 -0
  130. data/samples/processing_app/basics/math/noise_3_d.rb +50 -0
  131. data/samples/processing_app/basics/math/noise_wave.rb +61 -0
  132. data/samples/processing_app/basics/math/operator_precedence.rb +70 -0
  133. data/samples/processing_app/basics/math/polar_to_cartesian.rb +44 -0
  134. data/samples/processing_app/basics/math/random.rb +35 -0
  135. data/samples/processing_app/basics/math/sine.rb +49 -0
  136. data/samples/processing_app/basics/math/sine_cosine.rb +60 -0
  137. data/samples/processing_app/basics/math/sine_wave.rb +62 -0
  138. data/samples/processing_app/basics/objects/composite_objects.rb +139 -0
  139. data/samples/processing_app/basics/objects/inheritance.rb +104 -0
  140. data/samples/processing_app/basics/objects/multiple_constructors.rb +66 -0
  141. data/samples/processing_app/basics/objects/objects.rb +72 -0
  142. data/samples/processing_app/basics/shape/data/bot1.svg +160 -0
  143. data/samples/processing_app/basics/shape/data/usa-wikipedia.svg +452 -0
  144. data/samples/processing_app/basics/shape/disable_style.rb +36 -0
  145. data/samples/processing_app/basics/shape/get_child.rb +43 -0
  146. data/samples/processing_app/basics/shape/load_display_shape.rb +33 -0
  147. data/samples/processing_app/basics/shape/scale_shape.rb +33 -0
  148. data/samples/processing_app/basics/structure/coordinates.rb +55 -0
  149. data/samples/processing_app/basics/structure/create_graphics.rb +39 -0
  150. data/samples/processing_app/basics/structure/functions.rb +41 -0
  151. data/samples/processing_app/basics/structure/loop.rb +39 -0
  152. data/samples/processing_app/basics/structure/noloop.rb +33 -0
  153. data/samples/processing_app/basics/structure/recursion1.rb +42 -0
  154. data/samples/processing_app/basics/structure/recursion2.rb +39 -0
  155. data/samples/processing_app/basics/structure/redraw.rb +36 -0
  156. data/samples/processing_app/basics/structure/setup_draw.rb +30 -0
  157. data/samples/processing_app/basics/structure/statements_comments.rb +32 -0
  158. data/samples/processing_app/basics/structure/width_height.rb +29 -0
  159. data/samples/processing_app/basics/transform/arm.rb +47 -0
  160. data/samples/processing_app/basics/transform/rotate.rb +43 -0
  161. data/samples/processing_app/basics/transform/scale.rb +45 -0
  162. data/samples/processing_app/basics/transform/translate.rb +41 -0
  163. data/samples/processing_app/basics/transform/triangle_flower.rb +69 -0
  164. data/samples/processing_app/basics/typography/data/CourierNew36.vlw +0 -0
  165. data/samples/processing_app/basics/typography/data/Ziggurat-HTF-Black-32.vlw +0 -0
  166. data/samples/processing_app/basics/typography/letters.rb +52 -0
  167. data/samples/processing_app/basics/typography/words.rb +37 -0
  168. data/samples/processing_app/basics/web/embedded_links.rb +58 -0
  169. data/samples/processing_app/basics/web/loading_images.rb +25 -0
  170. metadata +181 -86
  171. data/lib/patches/JRubyApplet.diff +0 -24
  172. data/lib/patches/PATCHES.txt +0 -3
  173. data/lib/patches/PApplet.diff +0 -27
  174. data/library/minim/license.txt +0 -339
  175. data/library/minim/version.txt +0 -1
  176. data/library/opengl/library/gluegen-rt-natives-linux-amd64.jar +0 -0
  177. data/library/opengl/library/gluegen-rt-natives-linux-i586.jar +0 -0
  178. data/library/opengl/library/gluegen-rt-natives-macosx-ppc.jar +0 -0
  179. data/library/opengl/library/gluegen-rt-natives-macosx-universal.jar +0 -0
  180. data/library/opengl/library/gluegen-rt-natives-windows-amd64.jar +0 -0
  181. data/library/opengl/library/gluegen-rt-natives-windows-i586.jar +0 -0
  182. data/library/opengl/library/gluegen-rt.jar.pack.gz +0 -0
  183. data/library/opengl/library/jogl-natives-linux-amd64.jar +0 -0
  184. data/library/opengl/library/jogl-natives-linux-i586.jar +0 -0
  185. data/library/opengl/library/jogl-natives-macosx-ppc.jar +0 -0
  186. data/library/opengl/library/jogl-natives-macosx-universal.jar +0 -0
  187. data/library/opengl/library/jogl-natives-windows-amd64.jar +0 -0
  188. data/library/opengl/library/jogl-natives-windows-i586.jar +0 -0
  189. data/library/opengl/library/jogl.jar.pack.gz +0 -0
  190. data/library/pdf/notes.txt +0 -8
  191. data/library/serial/library/librxtxSerial.jnilib +0 -0
  192. data/library/serial/library/librxtxSerial.so +0 -0
  193. data/library/serial/library/rxtxSerial.dll +0 -0
@@ -0,0 +1,50 @@
1
+ # Noise3D.
2
+ #
3
+ # Using 3D noise to create simple animated texture.
4
+ # Here, the third dimension ('z') is treated as time.
5
+
6
+ class Noise3D < Processing::App
7
+
8
+ def setup
9
+
10
+ size 200, 200
11
+ frame_rate 30
12
+
13
+ @increment = 0.01
14
+ @zoff = 0.0
15
+ @z_increment = 0.02
16
+
17
+ end
18
+
19
+ def draw
20
+
21
+ background 0
22
+
23
+ load_pixels
24
+
25
+ xoff = 0.0
26
+
27
+ (0...width).each { |x|
28
+
29
+ xoff += @increment
30
+ yoff = 0.0
31
+
32
+ (0...height).each { |y|
33
+
34
+ yoff += @increment
35
+
36
+ bright = noise( xoff, yoff, @zoff ) * 255
37
+
38
+ pixels[x+y*width] = color bright
39
+ }
40
+ }
41
+
42
+ update_pixels
43
+
44
+ @zoff += @z_increment
45
+
46
+ end
47
+
48
+ end
49
+
50
+ Noise3D.new :title => "Noise 3 D"
@@ -0,0 +1,61 @@
1
+ # Noise Wave
2
+
3
+ class NoiseWave < Processing::App
4
+
5
+ def setup
6
+
7
+ size 200, 200
8
+ frame_rate 30
9
+
10
+ color_mode RGB, 255, 255, 255, 100
11
+ smooth
12
+ @w = width + 16
13
+ @y_values = []
14
+ @x_spacing = 8
15
+ @yoff = 0.0
16
+
17
+ end
18
+
19
+ def draw
20
+
21
+ background 0
22
+
23
+ calc_wave
24
+ draw_wave
25
+
26
+ end
27
+
28
+ def calc_wave
29
+
30
+ dx = 0.05
31
+ dy = 0.01
32
+ amplitude = 100.0
33
+
34
+ @yoff += dy
35
+
36
+ xoff = @yoff
37
+
38
+ (0...(@w/@x_spacing)).each { |i|
39
+
40
+ @y_values[i] = (2 * noise(xoff) - 1) * amplitude
41
+ xoff += dx
42
+ }
43
+
44
+ end
45
+
46
+ def draw_wave
47
+
48
+ no_stroke
49
+ fill 255, 50
50
+ ellipse_mode CENTER
51
+
52
+ @y_values.each_with_index { |v, x|
53
+
54
+ ellipse x * @x_spacing, width/2 + v, 16, 16
55
+ }
56
+
57
+ end
58
+
59
+ end
60
+
61
+ NoiseWave.new :title => "Noise Wave"
@@ -0,0 +1,70 @@
1
+ # Operator Precedence
2
+ #
3
+ # If you don't explicitly state the order in which
4
+ # an expression is evaluated, they are evaluated based
5
+ # on the operator precedence. For example, in the statement
6
+ # "4+2*8", the 2 will first be multiplied by 8 and then the result will
7
+ # be added to 4. This is because the "*" has a higher precedence
8
+ # than the "+". To avoid ambiguity in reading the program,
9
+ # it is recommended that is statement is written as "4+(2*8)".
10
+ # The order of evaluation can be controlled through placement of
11
+ # parenthesis in the code. A table of operator precedence follows below.
12
+
13
+ # The highest precedence is at the top of the list and
14
+ # the lowest is at the bottom.
15
+ # Multiplicative: * / %
16
+ # Additive: + -
17
+ # Relational: < > <= >=
18
+ # Equality: == !=
19
+ # Logical AND: &&
20
+ # Logical OR: ||
21
+ # Assignment: = += -= *= /= %=
22
+
23
+ class OperatorPrecedence < Processing::App
24
+
25
+ def setup
26
+
27
+ size 200, 200
28
+
29
+ background 51
30
+
31
+ no_fill
32
+ stroke 204
33
+
34
+ (0...(width-20)).step( 4 ) { |i|
35
+
36
+ # The 30 is added to 70 and then evaluated
37
+ # if it is greater than the current value of "i"
38
+ # For clarity, write as "if i > (30 + 70))"
39
+
40
+ line i, 0, i, 50 if i > 30 + 70
41
+ }
42
+
43
+ stroke 255
44
+
45
+ # The 2 is multiplied by the 8 and the result is added to the 4
46
+ # For clarity, write as "rect 4 + (2 * 8), 52, 90, 48"
47
+
48
+ rect( 4 + 2 * 8, 52, 90, 48 )
49
+ rect( (4 + 2) * 8, 100, 90, 49 )
50
+
51
+ stroke 153
52
+
53
+ (0...width).step( 2 ) { |i|
54
+
55
+ # The relational statements are evaluated
56
+ # first, and then the logical AND statements and
57
+ # finally the logical OR. For clarity, write as:
58
+ # "if ((i > 20) && (i < 50)) || ((i > 100) && (i < 180))"
59
+
60
+ line i, 151, i, height-1 if i > 20 && i < 50 || i > 100 && i < width-20
61
+ }
62
+ end
63
+
64
+ def draw
65
+
66
+ end
67
+
68
+ end
69
+
70
+ OperatorPrecedence.new :title => "Operator Precedence"
@@ -0,0 +1,44 @@
1
+ # PolarToCartesian
2
+ # by Daniel Shiffman.
3
+ #
4
+ # Convert a polar coordinate (r,theta) to cartesian (x,y):
5
+ # x = r * cos(theta)
6
+ # y = r * sin(theta)
7
+
8
+ class PolarToCartesian < Processing::App
9
+
10
+ def setup
11
+
12
+ size 200, 200
13
+
14
+ frame_rate 30
15
+ smooth
16
+
17
+ @r = 50.0
18
+ @theta = 0.0
19
+ @theta_vel = 0.0
20
+ @theta_acc = 0.1e-3
21
+ end
22
+
23
+ def draw
24
+
25
+ background 0
26
+
27
+ translate width/2, height/2
28
+
29
+ x = @r * cos( @theta )
30
+ y = @r * sin( @theta )
31
+
32
+ ellipse_mode CENTER
33
+ no_stroke
34
+ fill 200
35
+ ellipse x, y, 16, 16
36
+
37
+ @theta_vel += @theta_acc
38
+ @theta += @theta_vel
39
+
40
+ end
41
+
42
+ end
43
+
44
+ PolarToCartesian.new :title => "Polar To Cartesian"
@@ -0,0 +1,35 @@
1
+ # Random.
2
+ #
3
+ # Random numbers create the basis of this image.
4
+ # Each time the program is loaded the result is different.
5
+
6
+ class Random < Processing::App
7
+
8
+ def setup
9
+
10
+ size 200, 200
11
+
12
+ smooth
13
+ stroke_weight 10
14
+
15
+ no_loop
16
+
17
+ end
18
+
19
+ def draw
20
+
21
+ background 0
22
+
23
+ (0...width).each { |i|
24
+
25
+ r = random 255
26
+ x = random 0, width
27
+ stroke r, 100
28
+ line i, 0, x, height
29
+ }
30
+
31
+ end
32
+
33
+ end
34
+
35
+ Random.new :title => "Random"
@@ -0,0 +1,49 @@
1
+ # Sine.
2
+ #
3
+ # Smoothly scaling size with the sin() function.
4
+
5
+ class Sine < Processing::App
6
+
7
+ def setup
8
+
9
+ size 200, 200
10
+ no_stroke
11
+ smooth
12
+
13
+ @diameter = 84.0
14
+ @sin = 0.0
15
+ @angle = 0.0
16
+ @rad_points = 90
17
+
18
+ end
19
+
20
+ def draw
21
+
22
+ background 153
23
+
24
+ translate 130, 65
25
+
26
+ fill 255
27
+ ellipse 0, 0, 16, 16
28
+
29
+ angle_rot = 0.0
30
+ fill 51
31
+
32
+ (0...5).each { |i|
33
+
34
+ push_matrix
35
+ rotate angle_rot - 45
36
+ ellipse -116, 0, @diameter, @diameter
37
+ pop_matrix
38
+ angle_rot += TWO_PI/5
39
+ }
40
+
41
+ @diameter = 34 * sin( @angle ) + 168
42
+ @angle += 0.02
43
+ #@angle = 0.0 if @angle > TWO_PI
44
+
45
+ end
46
+
47
+ end
48
+
49
+ Sine.new :title => "Sine"
@@ -0,0 +1,60 @@
1
+ # Sine Cosine.
2
+ #
3
+ # Linear movement with sin() and cos().
4
+ # Numbers between 0 and PI*2 (TWO_PI which is roughly 6.28)
5
+ # are put into these functions and numbers between -1 and 1 are
6
+ # returned. These values are then scaled to produce larger movements.
7
+
8
+ class SineCosine < Processing::App
9
+
10
+ def setup
11
+
12
+ size 200, 200
13
+ no_stroke
14
+ smooth
15
+
16
+ @i = 45
17
+ @j = 225
18
+ @pos1 = 0.0
19
+ @pos2 = 0.0
20
+ @pos3 = 0.0
21
+ @pos4 = 0.0
22
+ @sc = 40
23
+
24
+ end
25
+
26
+ def draw
27
+
28
+ background 0
29
+
30
+ fill 51
31
+ rect 60, 60, 80, 80
32
+
33
+ fill 255
34
+ ellipse @pos1, 36, 32, 32
35
+
36
+ fill 153
37
+ ellipse 36, @pos2, 32, 32
38
+
39
+ fill 255
40
+ ellipse @pos3, 164, 32, 32
41
+
42
+ fill 153
43
+ ellipse 164, @pos4, 32, 32
44
+
45
+ @i += 3
46
+ @j -= 3
47
+
48
+ ang1 = radians @i
49
+ ang2 = radians @j
50
+
51
+ @pos1 = width/2 + (@sc * cos( ang1 ))
52
+ @pos2 = width/2 + (@sc * sin( ang1 ))
53
+ @pos3 = width/2 + (@sc * cos( ang2 ))
54
+ @pos4 = width/2 + (@sc * sin( ang2 ))
55
+
56
+ end
57
+
58
+ end
59
+
60
+ SineCosine.new :title => "Sine Cosine"
@@ -0,0 +1,62 @@
1
+ # Sine Wave
2
+ # by Daniel Shiffman.
3
+ #
4
+ # Render a simple sine wave.
5
+
6
+ class SineWave < Processing::App
7
+
8
+ def setup
9
+
10
+ size 200, 200
11
+
12
+ frame_rate 30
13
+ color_mode RGB, 255, 255, 255, 100
14
+ smooth
15
+
16
+ @w = width + 16
17
+ @period = 500.0
18
+ @x_spacing = 8
19
+ @dx = (TWO_PI / @period) * @x_spacing
20
+ @y_values = []
21
+ @theta = 0.0
22
+ @amplitude = 75.0
23
+
24
+ end
25
+
26
+ def draw
27
+
28
+ background 0
29
+ calc_wave
30
+ draw_wave
31
+
32
+ end
33
+
34
+ def calc_wave
35
+
36
+ @theta += 0.02
37
+
38
+ x = @theta
39
+ (0...(@w/@x_spacing)).each { |i|
40
+
41
+ @y_values[i] = sin(x) * @amplitude
42
+ x += @dx
43
+ }
44
+
45
+ end
46
+
47
+ def draw_wave
48
+
49
+ no_stroke
50
+ fill 255, 50
51
+ ellipse_mode CENTER
52
+
53
+ @y_values.each_with_index { |v, x|
54
+
55
+ ellipse x*@x_spacing, width/2+v, 16, 16
56
+ }
57
+
58
+ end
59
+
60
+ end
61
+
62
+ SineWave.new :title => "Sine Wave"
@@ -0,0 +1,139 @@
1
+ # Composite Objects
2
+ #
3
+ # An object can include several other objects. Creating such composite objects
4
+ # is a good way to use the principles of modularity and build higher levels of
5
+ # abstraction within a program.
6
+
7
+ class CompositeObjects < Processing::App
8
+
9
+ def setup
10
+
11
+ size 200, 200
12
+ smooth
13
+ @er1 = EggRing.new 66, 132, 0.1, 66
14
+ @er2 = EggRing.new 132, 180, 0.05, 132
15
+ end
16
+
17
+ def draw
18
+
19
+ background 0
20
+
21
+ [@er1, @er2].each do |er| er.transmit end
22
+ end
23
+
24
+ # vvv CLASS EGG RING
25
+
26
+ class EggRing
27
+
28
+ def initialize ( x, y, t, sp )
29
+
30
+ @ovoid = Egg.new x, y, t, sp
31
+ @circle = Ring.new
32
+ @circle.start x, y - sp/2
33
+ end
34
+
35
+ def transmit
36
+
37
+ @ovoid.wobble
38
+ @ovoid.display
39
+ @circle.grow
40
+ @circle.display
41
+ @circle.on = true unless @circle.on
42
+ end
43
+
44
+ end
45
+
46
+ # ^^^ CLASS EGG RING
47
+
48
+ # vvv CLASS EGG
49
+
50
+ class Egg
51
+
52
+ attr_accessor :x, :y # these are (or better generate) getters/setters
53
+ # for these instance variables
54
+ attr_accessor :tilt
55
+ attr_accessor :angle
56
+ attr_accessor :scalar
57
+
58
+ def initialize ( x, y, t, s )
59
+
60
+ @x, @y = x, y # the @-sign means that these are instance variables
61
+ @tilt = t
62
+ @scalar = s / 100.0
63
+ @angle = 0.0
64
+ end
65
+
66
+ def wobble
67
+
68
+ @tilt = Math.cos( @angle ) / 8
69
+ @angle += 0.1
70
+ end
71
+
72
+ def display
73
+
74
+ no_stroke # in Ruby-Processing classes defined inside the main sketch
75
+ # class automatically inherit the Processing commands, just
76
+ # like "inner classes" in Java
77
+ fill 255
78
+
79
+ push_matrix
80
+
81
+ translate @x, @y
82
+ rotate @tilt
83
+ scale @scalar
84
+
85
+ begin_shape
86
+
87
+ vertex 0, -100
88
+ bezier_vertex 25, -100, 40, -65, 40, -40
89
+ bezier_vertex 40, -15, 25, 0, 0, 0
90
+ bezier_vertex -25, 0, -40, -15, -40, -40
91
+ bezier_vertex -40, -65, -25, -100, 0, -100
92
+
93
+ end_shape
94
+
95
+ pop_matrix
96
+ end
97
+
98
+ end
99
+
100
+ # ^^^ CLASS EGG
101
+
102
+ # vvv CLASS RING
103
+
104
+ class Ring
105
+
106
+ attr_accessor :x, :y
107
+ attr_accessor :diameter
108
+ attr_accessor :on
109
+
110
+ def start ( xpos, ypos )
111
+
112
+ @x, @y = xpos, ypos
113
+ @on = true
114
+ @diameter = 1.0
115
+ end
116
+
117
+ def grow
118
+
119
+ @diameter += 0.5 if @on
120
+ @diameter = 0.0 if @diameter > width*2
121
+ end
122
+
123
+ def display
124
+
125
+ if @on
126
+ no_fill
127
+ stroke_weight 4
128
+ stroke 155, 153
129
+ ellipse @x, @y, @diameter, @diameter
130
+ end
131
+ end
132
+
133
+ end
134
+
135
+ # ^^^ CLASS RING
136
+
137
+ end
138
+
139
+ CompositeObjects.new :title => "Composite Objects"