ruby-processing 2.4.4 → 2.5.0

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 (227) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rpextras.jar +0 -0
  3. data/lib/ruby-processing.rb +8 -6
  4. data/lib/ruby-processing/app.rb +54 -67
  5. data/lib/ruby-processing/config.rb +7 -7
  6. data/lib/ruby-processing/exporters/application_exporter.rb +37 -38
  7. data/lib/ruby-processing/exporters/base_exporter.rb +34 -37
  8. data/lib/ruby-processing/exporters/creator.rb +27 -25
  9. data/lib/ruby-processing/helper_methods.rb +18 -22
  10. data/lib/ruby-processing/helpers/numeric.rb +5 -6
  11. data/lib/ruby-processing/helpers/string.rb +11 -20
  12. data/lib/ruby-processing/library_loader.rb +33 -35
  13. data/lib/ruby-processing/runner.rb +118 -65
  14. data/lib/ruby-processing/runners/base.rb +21 -26
  15. data/lib/ruby-processing/runners/live.rb +3 -4
  16. data/lib/ruby-processing/runners/run.rb +1 -3
  17. data/lib/ruby-processing/runners/watch.rb +8 -8
  18. data/lib/ruby-processing/version.rb +1 -1
  19. data/lib/templates/application/lib/args.txt.erb +1 -1
  20. data/lib/templates/application/run.erb +3 -3
  21. data/library/control_panel/control_panel.rb +29 -29
  22. data/library/fastmath/fastmath.rb +3 -0
  23. data/library/file_chooser/file_chooser.rb +11 -13
  24. data/library/vecmath/vecmath.rb +6 -35
  25. data/samples/Rakefile +3 -1
  26. data/samples/configRP5/configRP5.pde +150 -0
  27. data/samples/contributed/Rakefile +6 -6
  28. data/samples/contributed/animator.rb +6 -6
  29. data/samples/contributed/bezier_playground.rb +29 -68
  30. data/samples/contributed/circle_collision.rb +6 -13
  31. data/samples/contributed/elegant_ball.rb +14 -17
  32. data/samples/contributed/empathy.rb +8 -5
  33. data/samples/contributed/fibonacci_sphere.rb +10 -49
  34. data/samples/contributed/full_screen.rb +1 -1
  35. data/samples/contributed/grapher.rb +10 -9
  36. data/samples/contributed/gravity.rb +11 -16
  37. data/samples/contributed/jwishy.rb +18 -20
  38. data/samples/contributed/quadraticvertex.rb +26 -26
  39. data/samples/external_library/java_processing/custom/landscape.rb +6 -4
  40. data/samples/external_library/java_processing/hemesh/twin_iso.rb +69 -71
  41. data/samples/external_library/java_processing/pbox2d/bumpy_surface_noise.rb +57 -0
  42. data/samples/external_library/java_processing/pbox2d/contact_test.rb +23 -0
  43. data/samples/external_library/java_processing/pbox2d/data/java_args.txt +2 -0
  44. data/samples/external_library/java_processing/pbox2d/library/custom_shape/custom_shape.rb +158 -0
  45. data/samples/external_library/java_processing/pbox2d/library/particle_system/particle_system.rb +212 -0
  46. data/samples/external_library/java_processing/pbox2d/library/surface/surface.rb +154 -0
  47. data/samples/external_library/java_processing/pbox2d/liquidy.rb +58 -0
  48. data/samples/external_library/java_processing/pbox2d/polygons.rb +58 -0
  49. data/samples/external_library/java_processing/toxiclibs/library/vbo/vbo.rb +52 -0
  50. data/samples/external_library/java_processing/toxiclibs/model_align.rb +9 -16
  51. data/samples/processing_app/basics/color/color_wheel.rb +1 -1
  52. data/samples/processing_app/basics/form/regular_polygon.rb +2 -2
  53. data/samples/processing_app/basics/form/rgb_cube.rb +2 -2
  54. data/samples/processing_app/basics/form/shape_primitives.rb +1 -1
  55. data/samples/processing_app/basics/form/star.rb +2 -2
  56. data/samples/processing_app/basics/input/clock.rb +21 -16
  57. data/samples/processing_app/basics/input/storing_input.rb +6 -6
  58. data/samples/processing_app/basics/math/additive_wave.rb +1 -1
  59. data/samples/processing_app/basics/math/sine.rb +2 -2
  60. data/samples/processing_app/basics/math/sine_cosine.rb +1 -1
  61. data/samples/processing_app/basics/math/sine_wave.rb +1 -1
  62. data/samples/processing_app/basics/objects/inheritance.rb +2 -0
  63. data/samples/processing_app/basics/objects/inheritance_two.rb +88 -0
  64. data/samples/processing_app/basics/objects/module.rb +89 -0
  65. data/samples/processing_app/{library/vecmath/drawolver.rb → basics/objects/module_two.rb} +1 -1
  66. data/samples/processing_app/basics/objects/multiple_constructors.rb +5 -0
  67. data/samples/processing_app/basics/objects/struct.rb +38 -0
  68. data/samples/processing_app/basics/structure/recursion2.rb +1 -1
  69. data/samples/processing_app/basics/transform/birds.rb +7 -10
  70. data/samples/processing_app/basics/transform/library/bird/bird.rb +3 -3
  71. data/samples/processing_app/basics/transform/rotate.rb +1 -1
  72. data/samples/processing_app/basics/transform/rotate1.rb +1 -1
  73. data/samples/processing_app/basics/transform/rotate_x_y.rb +1 -1
  74. data/samples/processing_app/demos/graphics/bezier_patch.rb +1 -38
  75. data/samples/processing_app/demos/graphics/trefoil.rb +50 -40
  76. data/samples/processing_app/demos/graphics/wiggling.rb +36 -38
  77. data/samples/processing_app/demos/performance/cubic_grid_retained.rb +14 -14
  78. data/samples/processing_app/demos/performance/esfera.rb +27 -39
  79. data/samples/processing_app/demos/performance/text_rendering.rb +1 -1
  80. data/samples/processing_app/library/fastmath/clock.rb +44 -0
  81. data/samples/processing_app/library/pdf/complex_3D.rb +26 -24
  82. data/samples/processing_app/library/vecmath/{Rakefile → arcball/Rakefile} +6 -6
  83. data/samples/processing_app/library/vecmath/arcball/arcball_box.rb +23 -0
  84. data/samples/processing_app/library/vecmath/arcball/arcball_radius.rb +23 -0
  85. data/samples/processing_app/library/vecmath/arcball/arcball_shape.rb +29 -0
  86. data/samples/processing_app/library/vecmath/{README.txt → vec2d/README.txt} +0 -0
  87. data/samples/processing_app/library/vecmath/vec2d/Rakefile +30 -0
  88. data/samples/processing_app/library/vecmath/{acceleration_with_vectors.rb → vec2d/acceleration_with_vectors.rb} +4 -5
  89. data/samples/processing_app/library/vecmath/{bouncing_ball.rb → vec2d/bouncing_ball.rb} +9 -15
  90. data/samples/processing_app/library/vecmath/{circle_collision.rb → vec2d/circle_collision.rb} +46 -51
  91. data/samples/processing_app/library/vecmath/{data → vec2d/data}/java_args.txt +0 -0
  92. data/samples/processing_app/library/vecmath/{data → vec2d/data}/sprite.png +0 -0
  93. data/samples/processing_app/library/vecmath/{data → vec2d/data}/texture.png +0 -0
  94. data/samples/processing_app/library/vecmath/{flocking.rb → vec2d/flocking.rb} +3 -6
  95. data/samples/processing_app/library/vecmath/{library → vec2d/library}/flock/flock.rb +47 -67
  96. data/samples/processing_app/library/vecmath/{library → vec2d/library}/particle/particle_system.rb +5 -5
  97. data/samples/processing_app/library/vecmath/vec2d/library/tile/tile.rb +85 -0
  98. data/samples/processing_app/library/vecmath/{morph.rb → vec2d/morph.rb} +17 -16
  99. data/samples/processing_app/library/vecmath/{multiple_particle_systems.rb → vec2d/multiple_particle_systems.rb} +11 -28
  100. data/samples/processing_app/library/vecmath/{particle_system_pshape.rb → vec2d/particle_system_pshape.rb} +4 -6
  101. data/samples/processing_app/library/vecmath/vec2d/penrose.rb +71 -0
  102. data/samples/processing_app/library/vecmath/{reflection1.rb → vec2d/reflection1.rb} +6 -6
  103. data/samples/processing_app/library/vecmath/{seeking_neural.rb → vec2d/seeking_neural.rb} +12 -16
  104. data/samples/processing_app/library/vecmath/{simple_particle_system.rb → vec2d/simple_particle_system.rb} +8 -12
  105. data/samples/processing_app/library/vecmath/{smoke_particle_system.rb → vec2d/smoke_particle_system.rb} +8 -13
  106. data/samples/processing_app/library/vecmath/{vector_math.rb → vec2d/vector_math.rb} +0 -0
  107. data/samples/processing_app/library/vecmath/{library/wiggler/wiggler.rb → vec2d/wiggle_pshape.rb} +28 -4
  108. data/samples/processing_app/library/vecmath/vec3d/Rakefile +30 -0
  109. data/samples/processing_app/library/vecmath/vec3d/drawolver.rb +86 -0
  110. data/samples/processing_app/library/vecmath/vec3d/frame_of_reference.rb +103 -0
  111. data/samples/processing_app/library/vecmath/{hilbert_fractal.rb → vec3d/hilbert_fractal.rb} +5 -33
  112. data/samples/processing_app/library/vecmath/vec3d/library/geometry/geometry.rb +3 -0
  113. data/samples/processing_app/library/vecmath/vec3d/library/geometry/lib/cylinder.rb +44 -0
  114. data/samples/processing_app/library/vecmath/vec3d/library/geometry/lib/mat4.rb +28 -0
  115. data/samples/processing_app/library/vecmath/vec3d/library/geometry/lib/plane.rb +60 -0
  116. data/samples/processing_app/library/vecmath/{library → vec3d/library}/hilbert/hilbert.rb +14 -17
  117. data/samples/processing_app/library/vecmath/{retained_menger.rb → vec3d/retained_menger.rb} +20 -55
  118. data/samples/processing_app/topics/advanced_data/Rakefile +6 -6
  119. data/samples/processing_app/topics/advanced_data/counting_words.rb +7 -7
  120. data/samples/processing_app/topics/advanced_data/data/data.xml +0 -15
  121. data/samples/processing_app/topics/advanced_data/data/struct_data.yml +5 -0
  122. data/samples/processing_app/topics/advanced_data/library/bubble/bubble.rb +8 -8
  123. data/samples/processing_app/topics/advanced_data/load_save_XML.rb +41 -42
  124. data/samples/processing_app/topics/advanced_data/load_save_json.rb +11 -11
  125. data/samples/processing_app/topics/advanced_data/load_save_struct_yaml.rb +22 -23
  126. data/samples/processing_app/topics/advanced_data/load_save_table.rb +12 -12
  127. data/samples/processing_app/topics/advanced_data/load_save_yaml.rb +10 -12
  128. data/samples/processing_app/topics/advanced_data/regex.rb +5 -6
  129. data/samples/processing_app/topics/advanced_data/threads.rb +27 -27
  130. data/samples/processing_app/topics/advanced_data/threads_two.rb +3 -2
  131. data/samples/processing_app/topics/advanced_data/word_frequency.rb +18 -16
  132. data/samples/processing_app/topics/advanced_data/yahoo_weather.rb +6 -5
  133. data/samples/processing_app/topics/animation/animated_sprite.rb +9 -7
  134. data/samples/processing_app/topics/animation/sequential.rb +19 -19
  135. data/samples/processing_app/topics/cellular_automata/library/ca/ca.rb +1 -1
  136. data/samples/processing_app/topics/cellular_automata/wolfram.rb +1 -1
  137. data/samples/processing_app/topics/create_shapes/begin_end_contour.rb +1 -1
  138. data/samples/processing_app/topics/create_shapes/library/wiggler/wiggler.rb +4 -4
  139. data/samples/processing_app/topics/create_shapes/particle_system_pshape.rb +2 -2
  140. data/samples/processing_app/topics/create_shapes/path_pshape.rb +1 -1
  141. data/samples/processing_app/topics/create_shapes/polygon_pshape_oo3.rb +1 -1
  142. data/samples/processing_app/topics/create_shapes/polygon_shape.rb +3 -3
  143. data/samples/processing_app/topics/file_io/load_file1.rb +1 -1
  144. data/samples/processing_app/topics/file_io/save_frames.rb +5 -5
  145. data/samples/processing_app/topics/file_io/save_one_image.rb +2 -2
  146. data/samples/processing_app/topics/file_io/tile_images.rb +1 -1
  147. data/samples/processing_app/topics/gui/scrollbar.rb +3 -3
  148. data/samples/processing_app/topics/image_processing/blending.rb +13 -13
  149. data/samples/processing_app/topics/image_processing/blur.rb +1 -1
  150. data/samples/processing_app/topics/image_processing/brightness.rb +1 -1
  151. data/samples/processing_app/topics/image_processing/convolution.rb +1 -1
  152. data/samples/processing_app/topics/image_processing/edge_detection.rb +4 -4
  153. data/samples/processing_app/topics/image_processing/explode.rb +1 -1
  154. data/samples/processing_app/topics/image_processing/extrusion.rb +1 -1
  155. data/samples/processing_app/topics/image_processing/histogram.rb +1 -1
  156. data/samples/processing_app/topics/image_processing/linear_image.rb +1 -1
  157. data/samples/processing_app/topics/image_processing/pixel_array.rb +1 -1
  158. data/samples/processing_app/topics/image_processing/zoom.rb +2 -2
  159. data/samples/processing_app/topics/lsystems/Rakefile +6 -6
  160. data/samples/processing_app/topics/lsystems/chequer.rb +4 -10
  161. data/samples/processing_app/topics/lsystems/csplant.rb +25 -25
  162. data/samples/processing_app/topics/lsystems/cstest.rb +9 -4
  163. data/samples/processing_app/topics/lsystems/david_tour.rb +14 -16
  164. data/samples/processing_app/topics/lsystems/koch.rb +8 -18
  165. data/samples/processing_app/topics/lsystems/library/cs_grammar/cs_grammar.rb +18 -24
  166. data/samples/processing_app/topics/lsystems/library/grammar/grammar.rb +7 -9
  167. data/samples/processing_app/topics/lsystems/library/koch/koch_fractal.rb +75 -94
  168. data/samples/processing_app/topics/lsystems/library/stochastic_grammar/stochastic_grammar.rb +11 -13
  169. data/samples/processing_app/topics/lsystems/mpeano.rb +29 -32
  170. data/samples/processing_app/topics/lsystems/peano.rb +19 -21
  171. data/samples/processing_app/topics/lsystems/penrose.rb +31 -37
  172. data/samples/processing_app/topics/lsystems/penrose_snowflake.rb +10 -15
  173. data/samples/processing_app/topics/lsystems/pentagonal.rb +20 -23
  174. data/samples/processing_app/topics/lsystems/snake_kolam.rb +13 -13
  175. data/samples/processing_app/topics/lsystems/stochastic_test.rb +25 -28
  176. data/samples/processing_app/topics/lsystems/three_d_tree.rb +25 -24
  177. data/samples/processing_app/topics/motion/bouncy_bubbles.rb +17 -17
  178. data/samples/processing_app/topics/motion/cubes_in_cube.rb +1 -3
  179. data/samples/processing_app/topics/motion/library/cube/cube.rb +2 -2
  180. data/samples/processing_app/topics/motion/reflection2.rb +1 -1
  181. data/samples/processing_app/topics/shaders/blur_filter.rb +3 -3
  182. data/samples/processing_app/topics/shaders/bw_shader.rb +3 -3
  183. data/samples/processing_app/topics/shaders/conway.rb +5 -5
  184. data/samples/processing_app/topics/shaders/deform.rb +5 -5
  185. data/samples/processing_app/topics/shaders/edge_detect.rb +3 -5
  186. data/samples/processing_app/topics/shaders/glossy_fish_eye.rb +15 -21
  187. data/samples/processing_app/topics/shaders/glsl_heightmap_noise.rb +21 -19
  188. data/samples/processing_app/topics/shaders/image_mask.rb +6 -6
  189. data/samples/processing_app/topics/shaders/landscape.rb +4 -4
  190. data/samples/processing_app/topics/shaders/monjori.rb +15 -15
  191. data/samples/processing_app/topics/shaders/nebula.rb +3 -3
  192. data/samples/processing_app/topics/shaders/sep_blur.rb +15 -15
  193. data/samples/processing_app/topics/shaders/toon_shading.rb +2 -2
  194. data/samples/processing_app/topics/simulate/chain.rb +16 -14
  195. data/samples/processing_app/topics/simulate/smoke_particle_system.rb +3 -3
  196. data/samples/processing_app/topics/vectors/acceleration_with_vectors.rb +3 -2
  197. data/samples/processing_app/topics/vectors/bouncing_ball.rb +1 -0
  198. data/samples/processing_app/topics/vectors/vector_math.rb +2 -1
  199. data/vendors/Rakefile +15 -3
  200. metadata +99 -86
  201. data/.gitignore +0 -13
  202. data/.travis.yml +0 -6
  203. data/.yardopts +0 -5
  204. data/CHANGELOG +0 -316
  205. data/CONTRIBUTING.md +0 -35
  206. data/Gemfile +0 -6
  207. data/LICENSE.md +0 -39
  208. data/README.md +0 -119
  209. data/Rakefile +0 -37
  210. data/bin/install_jruby_complete +0 -13
  211. data/lib/ruby-processing/exporters/exporters.rb +0 -7
  212. data/library/vecmath/lib/arcball.rb +0 -64
  213. data/library/vecmath/lib/quaternion.rb +0 -62
  214. data/library/vecmath/lib/vec.rb +0 -232
  215. data/ruby-processing.gemspec +0 -54
  216. data/samples/processing_app/library/pdf/.gitignore +0 -1
  217. data/samples/processing_app/library/vecmath/retained_test.rb +0 -65
  218. data/samples/processing_app/library/vecmath/retained_test2.rb +0 -65
  219. data/samples/processing_app/library/vecmath/wiggle_pshape.rb +0 -22
  220. data/test/README.md +0 -6
  221. data/test/basic.rb +0 -14
  222. data/test/draw_ex.rb +0 -12
  223. data/test/graphics.rb +0 -7
  224. data/test/p2d.rb +0 -14
  225. data/test/p3d.rb +0 -14
  226. data/test/rp5_test.rb +0 -86
  227. data/test/setup_ex.rb +0 -12
@@ -1,37 +1,37 @@
1
1
  #######################################################
2
- # Lindenmayer System in ruby-processing by Martin Prout
3
- # snake_kolam.rb using l-systems
2
+ # Lindenmayer System in ruby-procesDegLut.sing by Martin Prout
3
+ # snake_kolam.rb uDegLut.sing l-systems
4
4
  #######################################################
5
5
 
6
- load_library 'grammar'
6
+ load_library :grammar, :fastmath
7
7
 
8
8
  class SnakeKolam
9
9
  include Processing::Proxy
10
- import 'grammar'
10
+
11
11
  attr_accessor :axiom, :start_length, :xpos, :ypos, :grammar, :production, :draw_length, :gen
12
12
  XPOS = 0
13
13
  YPOS = 1
14
14
  ANGLE = 2
15
- DELTA = (PI/180) * 90.0 # convert degrees to radians
15
+ DELTA = 90 # degrees
16
16
 
17
17
  def initialize xpos, ypos
18
18
  setup_grammar
19
19
  @start_length = 120.0
20
- @theta = (PI/180) * 90.0 # convert degrees to radians
20
+ @theta = 90 # degrees
21
21
  @draw_length = start_length
22
22
  @xpos = xpos
23
23
  @ypos = ypos
24
24
  end
25
25
 
26
26
  def setup_grammar
27
- @axiom = "FX+F+FX+F"
27
+ @axiom = 'FX+F+FX+F'
28
28
  @grammar = Grammar.new(
29
29
  axiom,
30
- {"X" => "X-F-F+FX+F+FX-F-F+FX"}
30
+ {'X' => 'X-F-F+FX+F+FX-F-F+FX'}
31
31
  )
32
32
  end
33
33
 
34
- def render # NB not using affine transforms here
34
+ def render # NB not uDegLut.sing affine transforms here
35
35
  turtle = [xpos, ypos, 0.0]
36
36
  production.each do |element|
37
37
  case element
@@ -61,13 +61,13 @@ class SnakeKolam
61
61
 
62
62
  private
63
63
  ######################################################
64
- # draws line using current turtle and length parameters
64
+ # draws line uDegLut.sing current turtle and length parameters
65
65
  # returns a turtle corresponding to the new position
66
66
  ######################################################
67
67
 
68
68
  def draw_line(turtle, length)
69
- new_xpos = turtle[XPOS] + length * Math.cos(turtle[ANGLE])
70
- new_ypos = turtle[YPOS] + length * Math.sin(turtle[ANGLE])
69
+ new_xpos = turtle[XPOS] + length * DegLut.cos(turtle[ANGLE])
70
+ new_ypos = turtle[YPOS] + length * DegLut.sin(turtle[ANGLE])
71
71
  line(turtle[XPOS], turtle[YPOS], new_xpos, new_ypos)
72
72
  turtle = [new_xpos, new_ypos, turtle[ANGLE]]
73
73
  end
@@ -78,7 +78,7 @@ attr_reader :kolam
78
78
 
79
79
  def setup
80
80
  size 500, 500
81
- @kolam = SnakeKolam.new width/8, height*0.8
81
+ @kolam = SnakeKolam.new width / 8, height * 0.8
82
82
  kolam.create_grammar 3 # create grammar from rules
83
83
  no_loop
84
84
  end
@@ -2,54 +2,51 @@
2
2
  # stochastic_test.rb
3
3
  #
4
4
  # Lindenmayer System in ruby-processing by Martin Prout
5
- # Exploring terminals with minimum logic
5
+ # Exploring terminals with minimum logic
6
6
  ########################################################
7
7
 
8
- load_library 'stochastic_grammar'
8
+
9
+ load_library :stochastic_grammar, :fastmath
10
+
11
+ Turtle = Struct.new(:x, :y, :angle)
9
12
 
10
13
  class StochasticPlant
11
14
  include Processing::Proxy
12
15
 
13
- attr_reader :grammar, :axiom, :draw_length, :theta, :xpos, :ypos, :production
14
-
15
- XPOS = 0 # placeholders for turtle array
16
- YPOS = 1
17
- ANGLE = 2
16
+ attr_reader :grammar, :axiom, :draw_length, :turtle, :production
18
17
 
19
- DELTA = PI/8
18
+ DELTA = 23
20
19
 
21
- def initialize xpos_, ypos_
20
+ def initialize xpos, ypos
22
21
  @draw_length = 350
23
- @xpos = xpos_
24
- @ypos = ypos_
25
- @theta = HALF_PI # this way is up?
22
+ # use Struct as turtle
23
+ @turtle = Turtle.new(xpos, ypos, 90) # this way is up?
26
24
  setup_grammar
27
25
  end
28
26
 
29
27
  def setup_grammar
30
- @axiom = "F"
31
- @grammar = StochasticGrammar.new(axiom)
32
- grammar.add_rule("F", "F[+F]F[-F]F", 0.1)
33
- grammar.add_rule("F", "F[+F]F", 0.45)
34
- grammar.add_rule("F", "F[-F]F", 0.45)
28
+ @axiom = 'F'
29
+ @grammar = StochasticGrammar.new(axiom)
30
+ grammar.add_rule('F', 'F[+F]F[-F]F', 0.1)
31
+ grammar.add_rule('F', 'F[+F]F', 0.45)
32
+ grammar.add_rule('F', 'F[-F]F', 0.45)
35
33
  @production = axiom
36
34
  end
37
35
 
38
36
  def render
39
37
  stack = [] # ruby array as the turtle stack
40
- turtle = [xpos, ypos, theta] # ruby array as a turtle
41
38
  production.each_char do |element|
42
39
  case element
43
40
  when 'F' # NB NOT using affine transforms
44
- turtle = draw_line(turtle, draw_length)
41
+ @turtle = draw_line(turtle, draw_length)
45
42
  when '+'
46
- turtle[ANGLE] += DELTA
43
+ turtle.angle += DELTA
47
44
  when '-'
48
- turtle[ANGLE] -= DELTA
45
+ turtle.angle -= DELTA
49
46
  when '['
50
- stack.push(turtle.dup) # push a copy of the current turtle to stack
47
+ stack << turtle.dup # push a copy of the current turtle to stack
51
48
  when ']'
52
- turtle = stack.pop # assign current turtle to an instance popped from the stack
49
+ @turtle = stack.pop # assign current turtle to an instance popped from the stack
53
50
  else
54
51
  puts "Character '#{element}' is not in grammar"
55
52
  end
@@ -64,14 +61,14 @@ class StochasticPlant
64
61
  private
65
62
  ######################################################
66
63
  # draws a line using current turtle and length parameters
67
- # returns a turtle corresponding to the new position
64
+ # returns a new turtle corresponding to the next position
68
65
  ######################################################
69
66
 
70
67
  def draw_line(turtle, length)
71
- new_xpos = turtle[XPOS] + length * cos(turtle[ANGLE])
72
- new_ypos = turtle[YPOS] - length * sin(turtle[ANGLE])
73
- line(turtle[XPOS], turtle[YPOS], new_xpos, new_ypos)
74
- turtle = [new_xpos, new_ypos, turtle[ANGLE]]
68
+ new_xpos = turtle.x + length * DegLut.cos(turtle.angle)
69
+ new_ypos = turtle.y - length * DegLut.sin(turtle.angle)
70
+ line(turtle.x, turtle.y, new_xpos, new_ypos)
71
+ Turtle.new(new_xpos, new_ypos, turtle.angle)
75
72
  end
76
73
  end
77
74
 
@@ -6,21 +6,22 @@
6
6
  load_libraries :stochastic_grammar, :control_panel
7
7
  attr_reader :plant, :zoom, :rot_y, :panel
8
8
 
9
- def setup()
9
+ def setup
10
10
  size(800, 800, P3D)
11
11
  camera(400.0, 500.0, 200.0, 0.0, -160.0, 0.0,
12
12
  0.0, 1.0, 0.0)
13
13
  setup_panel
14
14
  @plant = Plant.new
15
15
  plant.create_grammar(5)
16
- no_stroke()
16
+ no_stroke
17
17
  @rot_y = 0
18
18
  end
19
19
 
20
20
 
21
21
  def setup_panel
22
22
  control_panel do |c|
23
- c.title = "Control:"
23
+ c.title = 'Control:'
24
+ c.look_feel 'Metal'
24
25
  c.slider :zoom, 1..8, 3
25
26
  c.slider :rot_y, -PI..PI, 0
26
27
  c.button :reset
@@ -33,7 +34,7 @@ def reset
33
34
  @zoom = 1
34
35
  end
35
36
 
36
- def draw()
37
+ def draw
37
38
  panel.set_visible true if self.visible
38
39
  background(0)
39
40
  rotate_y rot_y
@@ -53,42 +54,42 @@ class Plant
53
54
  attr_reader :grammar, :axiom, :production, :premis, :rule,
54
55
  :theta, :scale_factor, :distance, :phi
55
56
 
56
- def initialize()
57
- @axiom = "F"
57
+ def initialize
58
+ @axiom = 'F'
58
59
  @grammar = StochasticGrammar.new(axiom)
59
60
  @production = axiom
60
- @premis = "F"
61
- @rule = "F[&+F]F[->F][->F][&F]"
61
+ @premis = 'F'
62
+ @rule = 'F[&+F]F[->F][->F][&F]'
62
63
  @scale_factor = 0.8
63
64
  @distance = 8
64
- @theta = radians(28)
65
- @phi = radians(28)
65
+ @theta = 28.radians
66
+ @phi = 28.radians
66
67
  grammar.add_rule(premis, rule)
67
- no_stroke()
68
+ no_stroke
68
69
  end
69
70
 
70
- def render()
71
+ def render
71
72
  production.each_char do |ch|
72
73
  case(ch)
73
- when "F"
74
+ when 'F'
74
75
  fill(0, 200, 0)
76
+ translate(0, distance / -2, 0)
77
+ box(distance / 4 , distance, distance / 4)
75
78
  translate(0, distance/-2, 0)
76
- box(distance/4 , distance, distance/4)
77
- translate(0, distance/-2, 0)
78
- when "-"
79
+ when '-'
79
80
  rotateX(-theta)
80
- when "+"
81
+ when '+'
81
82
  rotateX(theta)
82
- when "&"
83
- rotateY(-phi % TWO_PI)
84
- when ">"
85
- rotateZ(phi % TWO_PI)
86
- when "<"
83
+ when '&'
84
+ rotateY(-phi % TAU)
85
+ when '>'
86
+ rotateZ(phi % TAU)
87
+ when '<'
87
88
  rotateZ(-phi)
88
- when "["
89
+ when '['
89
90
  push_matrix
90
91
  @distance = distance * scale_factor
91
- when "]"
92
+ when ']'
92
93
  pop_matrix
93
94
  @distance = distance / scale_factor
94
95
  else
@@ -1,7 +1,7 @@
1
1
  #
2
- # Bouncy Bubbles
3
- # based on code from Keith Peters.
4
- #
2
+ # Bouncy Bubbles
3
+ # based on code from Keith Peters.
4
+ #
5
5
  # Multiple-object collision.
6
6
  #
7
7
 
@@ -13,7 +13,7 @@ NUM_BALLS = 12
13
13
  attr_reader :balls, :id
14
14
 
15
15
  def setup
16
- size(640, 360)
16
+ size(640, 360)
17
17
  @balls = []
18
18
  (0 ... NUM_BALLS).each do |i|
19
19
  balls << Ball.new(rand(width), rand(height), rand(30 .. 70), i, balls)
@@ -24,9 +24,9 @@ end
24
24
 
25
25
  def draw
26
26
  background(0)
27
- (0 ... NUM_BALLS).each do |i|
28
- balls[i].collide
29
- balls[i].move
27
+ (0 ... NUM_BALLS).each do |i|
28
+ balls[i].collide
29
+ balls[i].move
30
30
  balls[i].display
31
31
  end
32
32
  end
@@ -34,7 +34,7 @@ end
34
34
  class Ball
35
35
  attr_accessor :vx, :vy
36
36
  attr_reader :x, :y, :diameter, :others, :id, :width, :height
37
-
37
+
38
38
  def initialize(xin, yin, din, idin, oin)
39
39
  @x = xin
40
40
  @y = yin
@@ -45,8 +45,8 @@ class Ball
45
45
  @others = oin
46
46
  @width = $app.width
47
47
  @height = $app.height
48
- end
49
-
48
+ end
49
+
50
50
  def collide
51
51
  ((id + 1) ... NUM_BALLS).each do |i|
52
52
  dx = others[i].x - x
@@ -54,7 +54,7 @@ class Ball
54
54
  sq_dist = dx*dx + dy*dy
55
55
  min_dist = (others[i].diameter/2 + diameter/2)
56
56
  sq_min_dist = min_dist * min_dist
57
- if (sq_dist < sq_min_dist)
57
+ if (sq_dist < sq_min_dist)
58
58
  angle = atan2(dy, dx)
59
59
  target_x = x + cos(angle) * min_dist
60
60
  target_y = y + sin(angle) * min_dist
@@ -65,30 +65,30 @@ class Ball
65
65
  others[i].vx += ax
66
66
  others[i].vy += ay
67
67
  end
68
-
68
+
69
69
  end
70
-
70
+
71
71
  def move
72
72
  @vy += GRAVITY
73
73
  @x += vx
74
74
  @y += vy
75
75
  if (x + diameter/2 > width)
76
76
  @x = width - diameter/2
77
- @vx *= FRICTION
77
+ @vx *= FRICTION
78
78
  elsif (x - diameter/2 < 0)
79
79
  @x = diameter/2
80
80
  @vx *= FRICTION
81
81
  end
82
-
82
+
83
83
  if (y + diameter/2 > height)
84
84
  @y = height - diameter/2
85
- @vy *= FRICTION
85
+ @vy *= FRICTION
86
86
  elsif (y - diameter/2 < 0)
87
87
  @y = diameter/2
88
88
  @vy *= FRICTION
89
89
  end
90
90
  end
91
-
91
+
92
92
  def display
93
93
  ellipse(x, y, diameter, diameter)
94
94
  end
@@ -18,9 +18,7 @@ CUBE_NO = 20
18
18
  java_alias :background_int, :background, [Java::int]
19
19
  java_alias :stroke_int, :stroke, [Java::int]
20
20
 
21
- # using java_alias to give signatures to overloaded java method
22
- # in the cube class, need to call $app.fill_int in cube
23
- java_alias :fill_int, :fill, [Java::int]
21
+
24
22
 
25
23
  attr_reader :cubies
26
24
 
@@ -7,7 +7,7 @@ class Cube
7
7
  # Colors are hardcoded
8
8
  BOUNDS=300
9
9
  COLORS = [0, 51, 102, 153, 204, 255]
10
-
10
+
11
11
  # Position, velocity vectors
12
12
  attr_reader :position, :velocity, :rotation, :vertices, :w, :h, :d
13
13
  attr_reader :boundary
@@ -61,7 +61,7 @@ class Cube
61
61
  def draw_cube
62
62
  # Draw cube
63
63
  COLORS.length.times do |i|
64
- $app.fill_int(COLORS[i])
64
+ fill(COLORS[i])
65
65
  begin_shape(QUADS)
66
66
  4.times do |j|
67
67
  vertex(*vertices[j + 4 * i]) # splat vertices
@@ -47,7 +47,7 @@ def draw
47
47
 
48
48
  # Draw ground
49
49
  fill(127, 80, 70)
50
- begin_shape()
50
+ begin_shape
51
51
  ground.each do |seg|
52
52
  vertex(seg.x1, seg.y1)
53
53
  vertex(seg.x2, seg.y2)
@@ -10,14 +10,14 @@ attr_reader :blur
10
10
 
11
11
  def setup
12
12
  size(640, 360, P2D)
13
- @blur = load_shader("blur.glsl");
13
+ @blur = load_shader('blur.glsl')
14
14
  stroke(255, 0, 0)
15
15
  rectMode(CENTER)
16
16
  end
17
17
 
18
18
  def draw
19
- filter(blur);
20
- rect(mouse_x, mouse_y, 150, 150);
19
+ filter(blur)
20
+ rect(mouse_x, mouse_y, 150, 150)
21
21
  ellipse(mouse_x, mouse_y, 100, 100)
22
22
  end
23
23
 
@@ -5,9 +5,9 @@ attr_reader :label, :can, :angle, :bw_shader
5
5
 
6
6
  def setup
7
7
  size(640, 360, P3D)
8
- @label = load_image("lachoy.jpg")
8
+ @label = load_image('lachoy.jpg')
9
9
  @can = create_can(100, 200, 32, label)
10
- @bw_shader = load_shader("bwfrag.glsl")
10
+ @bw_shader = load_shader('bwfrag.glsl')
11
11
  @angle = 0
12
12
  end
13
13
 
@@ -27,7 +27,7 @@ def create_can(r, h, detail, tex)
27
27
  sh.no_stroke
28
28
  sh.texture(tex)
29
29
  (0 .. detail).each do |i|
30
- angle = TWO_PI / detail
30
+ angle = TAU / detail
31
31
  x = sin(i * angle)
32
32
  z = cos(i * angle)
33
33
  u = i.to_f / detail
@@ -8,15 +8,15 @@ def setup
8
8
  size(400, 400, P3D)
9
9
  @pg = createGraphics(400, 400, P2D)
10
10
  pg.no_smooth
11
- @conway = load_shader("data/conway.glsl")
12
- conway.set("resolution", width.to_f, height.to_f)
11
+ @conway = load_shader('data/conway.glsl')
12
+ conway.set('resolution', width.to_f, height.to_f)
13
13
  end
14
14
 
15
15
  def draw
16
- conway.set("time", millis() / 1000.0)
17
- xm = map(mouse_x, 0, width, 0, 1)
16
+ conway.set('time', millis / 1000.0)
17
+ xm = map(mouse_x, 0, width, 0, 1) # NB: processings map function
18
18
  ym = map(mouse_y, 0, height, 1, 0)
19
- conway.set("mouse", xm, ym)
19
+ conway.set('mouse', xm, ym)
20
20
  pg.begin_draw
21
21
  pg.background(0)
22
22
  pg.shader(conway)