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,7 +1,7 @@
1
1
  # Drawolver: draw 2D & revolve 3D
2
2
 
3
3
  # Example to show how to use the VecMath library.
4
- # Also the Array is extended to yield one_of_each
4
+ # Also the Array is extended to yield one_of_each using a module
5
5
  # pair of pts. See the drawolver library. Also features the use each_cons,
6
6
  # possibly a rare use for this ruby Enumerable method?
7
7
  # 2010-03-22 - fjenett (last revised by monkstone 2013-09-13)
@@ -14,6 +14,7 @@
14
14
  # But there are two ways to define methods with variable parameters. One is to give the
15
15
  # parameters a default value, the second is to use the catch-all asterix:
16
16
 
17
+
17
18
  # def my_method1 ( a, b = "2" ) # can be called with one or two arguments
18
19
  # end
19
20
 
@@ -21,6 +22,10 @@
21
22
  # end
22
23
 
23
24
 
25
+ # Martin Prout, 2014-06-23:
26
+ # even more flexibility can be had by passing a hash see inheritance_two @todo update for ruby-2.1+
27
+
28
+
24
29
  def setup
25
30
  size 640, 360
26
31
  background 204
@@ -0,0 +1,38 @@
1
+ #
2
+ # Storing Data as a Struct
3
+ #
4
+ # Move the mouse across the screen to change the position
5
+ # of the circles. The positions of the mouse are recorded
6
+ # into an array and played back every frame. Between each
7
+ # frame, the newest value are added to the end of each array
8
+ # and the oldest value is deleted.
9
+ #
10
+
11
+ NUM = 60
12
+
13
+ attr_reader :pos
14
+
15
+ Vec = Struct.new(:x, :y) # create named Struct Type with getters and setters
16
+
17
+ def setup
18
+ size(640, 360)
19
+ @pos = Array.new(NUM, Vec.new(0, 0)) # initialize a array of Struct
20
+ smooth(4)
21
+ no_stroke()
22
+ fill(255, 153)
23
+ end
24
+
25
+ def draw
26
+ background(51)
27
+
28
+ # Cycle through the array, using a different entry on each frame.
29
+ # Using modulo (%) like this is faster than moving all the values over.
30
+ which = frame_count % NUM
31
+ pos[which] = Vec.new(mouse_x, mouse_y)
32
+
33
+ (1 .. NUM).each do |i|
34
+ # which + 1 is the smallest (the oldest in the array)
35
+ idx = (which + i) % NUM
36
+ ellipse(pos[idx].x, pos[idx].y, i, i)
37
+ end
38
+ end
@@ -14,7 +14,7 @@ def draw_circle (x, y, radius, level)
14
14
  level = level - 1
15
15
  num = rand(2 .. 6)
16
16
  0.upto(num-1) do |i|
17
- a = rand(0 .. TWO_PI)
17
+ a = rand(0 .. TAU)
18
18
  nx = x + cos(a) * 8.0 * level
19
19
  ny = y + sin(a) * 6.0 * level
20
20
  draw_circle nx, ny, radius / 2, level
@@ -13,20 +13,17 @@ def setup
13
13
  size 640, 360, P3D
14
14
  no_stroke
15
15
  lights
16
- @birds = []
17
- 0.upto(BIRD_COUNT) do |i|
18
- bird = Bird.new rand(-300 .. 300), rand(-300 .. 300), rand(-2500 .. -500), rand(5 .. 30), rand(5 .. 30)
19
- bird.set_flight rand(20 .. 340), rand(30 .. 350), rand( 1000 .. 4800 ),
20
- rand(-160 .. 160), rand(-55 .. 55), rand(-20 .. 20)
21
- bird.set_wing_speed rand(0.1 .. 3.75)
22
- bird.set_rot_speed rand(0.025 .. 0.15)
23
- @birds << bird
24
- end
16
+ @birds = (0 .. BIRD_COUNT).map {
17
+ Bird.new(rand(-300 .. 300), rand(-300 .. 300), rand(-2500 .. -500), rand(5 .. 30), rand(5 .. 30))
18
+ .set_flight(rand(20 .. 340), rand(30 .. 350), rand( 1000 .. 4800 ), rand(-160 .. 160), rand(-55 .. 55), rand(-20 .. 20))
19
+ .set_wing_speed(rand(0.1 .. 3.75))
20
+ .set_rot_speed(rand(0.025 .. 0.15))
21
+ }
25
22
  end
26
23
 
27
24
  def draw
28
25
  background 0
29
26
  translate width/2, height/2, -700
30
- @birds.each {|b| b.fly}
27
+ @birds.map {|b| b.fly}
31
28
  end
32
29
 
@@ -28,19 +28,19 @@ class Bird
28
28
  end
29
29
 
30
30
  def set_flight ( radius_x, radius_y, radius_z, rot_x, rot_y, rot_z )
31
-
32
31
  @radius_x, @radius_y, @radius_z = radius_x, radius_y, radius_z
33
32
  @rot_x, @rot_y, @rot_z = rot_x, rot_y, rot_z
33
+ return self # return self means we can chain methods
34
34
  end
35
35
 
36
36
  def set_wing_speed ( flap_speed )
37
-
38
37
  @flap_speed = flap_speed
38
+ return self # return self means we can chain methods
39
39
  end
40
40
 
41
41
  def set_rot_speed ( rot_speed )
42
-
43
42
  @rot_speed = rot_speed
43
+ return self # return self means we can chain methods
44
44
  end
45
45
 
46
46
  def fly
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # Rotating a square around the Z axis. To get the results
4
4
  # you expect, send the rotate function angle parameters that are
5
- # values between 0 and PI*2 (TWO_PI which is roughly 6.28). If you prefer to
5
+ # values between 0 and PI*2 (TAU which is roughly 6.28). If you prefer to
6
6
  # think about angles as degrees (0-360), you can use the radians()
7
7
  # method to convert your values. For example: scale(radians(90))
8
8
  # is identical to the statement scale(PI/2).
@@ -16,7 +16,7 @@ end
16
16
  def draw
17
17
  background 0
18
18
  @a += 0.005
19
- @a = 0.0 if @a > TWO_PI
19
+ @a = 0.0 if @a > TAU
20
20
  translate width/2, height/2
21
21
  rotate_x @a
22
22
  rotate_y @a * 2
@@ -20,7 +20,7 @@ end
20
20
  def draw
21
21
  background(126)
22
22
  @a += 0.005
23
- @a = 0.0 if (a > TWO_PI)
23
+ @a = 0.0 if (a > TAU)
24
24
  translate(width/2, height/2)
25
25
 
26
26
  rotate_x(a)
@@ -19,7 +19,7 @@ attr_accessor :outp, :inp, :normp, :auto_normals, :arcball, :bez_patch
19
19
 
20
20
  def setup
21
21
  size(1024, 768, P3D)
22
- @arcball = ArcBall.new(width/2.0, height/2.0, min(width - 20, height - 20) * 0.5)
22
+ ArcBall.init(self, width/2.0, height/2.0)
23
23
  @auto_normals = false
24
24
  build_geometry
25
25
  @bez_patch = build_shape
@@ -27,12 +27,10 @@ end
27
27
 
28
28
  def draw
29
29
  background(255)
30
- translate(width/2,height/2)
31
30
  smooth(8)
32
31
  lights
33
32
  define_lights
34
33
  scale(0.9)
35
- update
36
34
  no_stroke
37
35
  shape(bez_patch)
38
36
  end
@@ -169,24 +167,6 @@ def d_bezier_blend( k, mu, n)
169
167
  return(dblendf)
170
168
  end
171
169
 
172
- ######################
173
- # ArcBall control
174
- # and lighting + re-run
175
- ######################
176
-
177
- def update
178
- theta, x, y, z = arcball.update
179
- rotate(theta, x, y, z)
180
- end
181
-
182
- def mouse_pressed
183
- arcball.mouse_pressed(mouse_x, mouse_y)
184
- end
185
-
186
- def mouse_dragged
187
- arcball.mouse_dragged(mouse_x, mouse_y)
188
- end
189
-
190
170
  def define_lights
191
171
  ambient_light(40, 40, 40)
192
172
  point_light(30, 30, 30, 0, 0, 0)
@@ -194,21 +174,4 @@ def define_lights
194
174
  spot_light(30, 30, 30, 0, 40, 200, 0, -0.5, 0.5, PI / 2, 2)
195
175
  end
196
176
 
197
- def key_pressed
198
- case(key)
199
- when ' '
200
- save_frame("bezPatch.png")
201
- build_geometry
202
- @bez_patch = build_shape
203
- when 'x'
204
- arcball.select_axis(X)
205
- when 'y'
206
- arcball.select_axis(Y)
207
- when 'z'
208
- arcball.select_axis(Z)
209
- end
210
- end
211
177
 
212
- def key_released
213
- arcball.select_axis(-1)
214
- end
@@ -1,6 +1,10 @@
1
1
  # Trefoil, by Andres Colubri
2
2
  # A parametric surface is textured procedurally
3
3
  # by drawing on an offscreen PGraphics surface.
4
+ #
5
+ # Features (Vec3D).to_normal(renderer) and (Vec3D).to_vertex_uv(renderer, u, v)
6
+ # see line 62 for inititialization of renderer where obj is an instance of PShape
7
+ # renderer = ShapeRender.new(obj)
4
8
 
5
9
  load_library :vecmath
6
10
 
@@ -10,7 +14,7 @@ def setup
10
14
  size(1024, 768, P3D)
11
15
 
12
16
  texture_mode(NORMAL)
13
- noStroke
17
+ no_stroke
14
18
 
15
19
  # Creating offscreen surface for 3D rendering.
16
20
  @pg = create_graphics(32, 512, P3D)
@@ -28,7 +32,7 @@ def draw
28
32
  background(0)
29
33
 
30
34
  pg.begin_draw
31
- pg.ellipse(rand * pg.width, rand * pg.height, 4, 4)
35
+ pg.ellipse(rand(0.0 .. pg.width), rand(0.0 .. pg.height), 4, 4)
32
36
  pg.end_draw
33
37
 
34
38
  ambient(250, 250, 250)
@@ -43,7 +47,7 @@ def draw
43
47
  end
44
48
 
45
49
  # Code to draw a trefoil knot surface, with normals and texture
46
- # coordinates.
50
+ # coordinates. Makes of the Vec3D Render interface (uses ShapeRender here).
47
51
  # Adapted from the parametric equations example by Philip Rideout:
48
52
  # http://iphone-3d-programming.labs.oreilly.com/ch03.html
49
53
 
@@ -52,12 +56,13 @@ end
52
56
  def create_trefoil(s, ny, nx, tex)
53
57
 
54
58
  obj = create_shape()
59
+
55
60
  obj.begin_shape(TRIANGLES)
56
61
  obj.texture(tex)
57
-
62
+ renderer = ShapeRender.new(obj)
58
63
  (0 ... nx).each do |j|
59
64
  u0 = j.to_f / nx
60
- u1 = (j + 1).to_f / nx
65
+ u1 = (j + 1).to_f / nx
61
66
  (0 ... ny).each do |i|
62
67
  v0 = i.to_f / ny
63
68
  v1 = (i + 1).to_f / ny
@@ -72,23 +77,23 @@ def create_trefoil(s, ny, nx, tex)
72
77
  n2 = eval_normal(u1, v1)
73
78
 
74
79
  # Triangle p0-p1-p2
75
- obj.normal(n0.x, n0.y, n0.z)
76
- obj.vertex(s * p0.x, s * p0.y, s * p0.z, u0, v0)
77
- obj.normal(n1.x, n1.y, n1.z)
78
- obj.vertex(s * p1.x, s * p1.y, s * p1.z, u0, v1)
79
- obj.normal(n2.x, n2.y, n2.z)
80
- obj.vertex(s * p2.x, s * p2.y, s * p2.z, u1, v1)
80
+ n0.to_normal(renderer)
81
+ (p0 * s).to_vertex_uv(renderer, u0, v0)
82
+ n1.to_normal(renderer)
83
+ (p1 * s).to_vertex_uv(renderer, u0, v1)
84
+ n2.to_normal(renderer)
85
+ (p2 * s).to_vertex_uv(renderer, u1, v1)
81
86
 
82
87
  p1 = eval_point(u1, v0)
83
88
  n1 = eval_normal(u1, v0)
84
89
 
85
90
  # Triangle p0-p2-p1
86
- obj.normal(n0.x, n0.y, n0.z)
87
- obj.vertex(s * p0.x, s * p0.y, s * p0.z, u0, v0)
88
- obj.normal(n2.x, n2.y, n2.z)
89
- obj.vertex(s * p2.x, s * p2.y, s * p2.z, u1, v1)
90
- obj.normal(n1.x, n1.y, n1.z)
91
- obj.vertex(s * p1.x, s * p1.y, s * p1.z, u1, v0)
91
+ n0.to_normal(renderer)
92
+ (p0 * s).to_vertex_uv(renderer, u0, v0)
93
+ n2.to_normal(renderer)
94
+ (p2 * s).to_vertex_uv(renderer, u1, v1)
95
+ n1.to_normal(renderer)
96
+ (p1 * s).to_vertex_uv(renderer, u1, v0)
92
97
  end
93
98
  end
94
99
  obj.end_shape
@@ -104,9 +109,7 @@ def eval_normal(u, v)
104
109
  tangV = eval_point(u, v + 0.01)
105
110
  tangU -= p
106
111
  tangV -= p
107
-
108
- normUV = tangV.cross(tangU)
109
- return normUV.normalize!
112
+ tangV.cross(tangU).normalize! # it is easy to chain Vec3D operations
110
113
  end
111
114
 
112
115
  # Evaluates the surface point corresponding to normalized
@@ -119,24 +122,31 @@ def eval_point(u, v)
119
122
  s = TAU * u
120
123
  t = (TAU * (1 - v)) * 2
121
124
 
122
- r = a + b * cos(1.5 * t)
123
- x = r * cos(t)
124
- y = r * sin(t)
125
- z = c * sin(1.5 * t)
126
-
127
- dv = Vec3D.new
128
- dv.x = -1.5 * b * sin(1.5 * t) * cos(t) - (a + b * cos(1.5 * t)) * sin(t)
129
- dv.y = -1.5 * b * sin(1.5 * t) * sin(t) + (a + b * cos(1.5 * t)) * cos(t)
130
- dv.z = 1.5 * c * cos(1.5 * t)
131
-
132
- dv.normalize!
133
- qvn = Vec3D.new(dv.y, -dv.x, 0)
134
- qvn.normalize!
135
- ww = dv.cross(qvn)
136
-
137
- pt = Vec3D.new
138
- pt.x = x + d * (qvn.x * cos(s) + ww.x * sin(s))
139
- pt.y = y + d * (qvn.y * cos(s) + ww.y * sin(s))
140
- pt.z = z + d * ww.z * sin(s)
141
- return pt
125
+ sint = sin(t)
126
+ cost = cos(t)
127
+ sint15 = sin(1.5 * t)
128
+ cost15 = cos(1.5 * t)
129
+
130
+ r = a + b * cost15
131
+ x = r * cost
132
+ y = r * sint
133
+ z = c * sint15
134
+
135
+ dv = Vec3D.new(
136
+ -1.5 * b * sint15 * cost - y,
137
+ -1.5 * b * sint15 * sint + x,
138
+ 1.5 * c * cost15)
139
+
140
+ q = dv.normalize # regular normalize creates a new Vec3D for us
141
+ qvn = Vec3D.new(q.y, -q.x, 0).normalize! # chained Vec3D operations
142
+
143
+ ww = q.cross(qvn)
144
+
145
+ coss = cos(s)
146
+ sins = sin(s)
147
+
148
+ Vec3D.new(
149
+ x + d * (qvn.x * coss + ww.x * sins),
150
+ y + d * (qvn.y * coss + ww.y * sins),
151
+ z + d * ww.z * sins)
142
152
  end
@@ -10,10 +10,20 @@ NOISE_MAG = 1.0
10
10
  # signature-specific alias for overloaded method
11
11
  java_alias :background_int, :background, [Java::int]
12
12
 
13
+ attr_reader :sine, :cosine
13
14
 
14
15
  def setup
15
- size(1024, 768, P3D);
16
- wiggling = false
16
+ size(1024, 768, P3D);
17
+ @sine = []
18
+ @cosine = []
19
+ wiggling = false
20
+ # Dry up that processing code a tiny bit
21
+ (0 .. TAU).step(TAU / CIRCLE_RES) do |i|
22
+ sine << CIRCLE_RAD * sin(i)
23
+ end
24
+ (0 .. TAU).step(TAU / CIRCLE_RES) do |i|
25
+ cosine << CIRCLE_RAD * cos(i)
26
+ end
17
27
  @cube = create_cube
18
28
  end
19
29
 
@@ -72,9 +82,8 @@ def create_cube
72
82
  face.end_contour
73
83
  face.begin_contour
74
84
  CIRCLE_RES.times do |i|
75
- angle = TAU * i / CIRCLE_RES
76
- x = CIRCLE_RAD * sin(angle)
77
- y = CIRCLE_RAD * cos(angle)
85
+ x = sine[i]
86
+ y = cosine[i]
78
87
  z = CUBE_SIZE / 2
79
88
  face.vertex(x, y, z)
80
89
  end
@@ -95,9 +104,8 @@ def create_cube
95
104
  face.end_contour
96
105
  face.begin_contour
97
106
  CIRCLE_RES.times do |i|
98
- angle = TAU * i / CIRCLE_RES
99
- x = CIRCLE_RAD * sin(angle)
100
- y = CIRCLE_RAD * cos(angle)
107
+ x = sine[i]
108
+ y = cosine[i]
101
109
  z = -CUBE_SIZE / 2
102
110
  face.vertex(x, y, z)
103
111
  end
@@ -118,10 +126,9 @@ def create_cube
118
126
  face.end_contour
119
127
  face.begin_contour
120
128
  CIRCLE_RES.times do |i|
121
- angle = TAU * i / CIRCLE_RES
122
129
  x = CUBE_SIZE / 2
123
- y = CIRCLE_RAD * sin(angle)
124
- z = CIRCLE_RAD * cos(angle)
130
+ y = sine[i]
131
+ z = cosine[i]
125
132
  face.vertex(x, y, z)
126
133
  end
127
134
  face.end_contour
@@ -141,10 +148,9 @@ def create_cube
141
148
  face.end_contour
142
149
  face.begin_contour
143
150
  CIRCLE_RES.times do |i|
144
- angle = TAU * i / CIRCLE_RES
145
151
  x = -CUBE_SIZE / 2
146
- y = CIRCLE_RAD * sin(angle)
147
- z = CIRCLE_RAD * cos(angle)
152
+ y = sine[i]
153
+ z = cosine[i]
148
154
  face.vertex(x, y, z)
149
155
  end
150
156
  face.end_contour
@@ -164,10 +170,9 @@ def create_cube
164
170
  face.end_contour
165
171
  face.begin_contour
166
172
  CIRCLE_RES.times do |i|
167
- angle = TAU * i / CIRCLE_RES
168
- x = CIRCLE_RAD * sin(angle)
173
+ x = sine[i]
169
174
  y = CUBE_SIZE / 2
170
- z = CIRCLE_RAD * cos(angle)
175
+ z = cosine[i]
171
176
  face.vertex(x, y, z)
172
177
  end
173
178
  face.end_contour
@@ -187,10 +192,9 @@ def create_cube
187
192
  face.end_contour
188
193
  face.begin_contour
189
194
  CIRCLE_RES.times do |i|
190
- angle = TAU * i / CIRCLE_RES
191
- x = CIRCLE_RAD * sin(angle)
195
+ x = sine[i]
192
196
  y = -CUBE_SIZE / 2
193
- z = CIRCLE_RAD * cos(angle)
197
+ z = cosine[i]
194
198
  face.vertex(x, y, z)
195
199
  end
196
200
  face.end_contour
@@ -209,9 +213,8 @@ def restore_cube
209
213
  face.set_vertex(2, CUBE_SIZE / 2, CUBE_SIZE / 2, CUBE_SIZE / 2)
210
214
  face.set_vertex(3, -CUBE_SIZE / 2, CUBE_SIZE / 2, CUBE_SIZE / 2)
211
215
  CIRCLE_RES.times do |i|
212
- angle = TAU * i / CIRCLE_RES
213
- x = CIRCLE_RAD * sin(angle)
214
- y = CIRCLE_RAD * cos(angle)
216
+ x = sine[i]
217
+ y = cosine[i]
215
218
  z = CUBE_SIZE / 2
216
219
  face.set_vertex(4 + i, x, y, z)
217
220
  end
@@ -223,9 +226,8 @@ def restore_cube
223
226
  face.set_vertex(2, -CUBE_SIZE / 2, CUBE_SIZE / 2, -CUBE_SIZE / 2)
224
227
  face.set_vertex(3, CUBE_SIZE / 2, CUBE_SIZE / 2, -CUBE_SIZE / 2)
225
228
  CIRCLE_RES.times do |i|
226
- angle = TAU * i / CIRCLE_RES
227
- x = CIRCLE_RAD * sin(angle)
228
- y = CIRCLE_RAD * cos(angle)
229
+ x = sine[i]
230
+ y = cosine[i]
229
231
  z = -CUBE_SIZE / 2
230
232
  face.set_vertex(4 + i, x, y, z)
231
233
  end
@@ -237,10 +239,9 @@ def restore_cube
237
239
  face.set_vertex(2, CUBE_SIZE / 2, CUBE_SIZE / 2, -CUBE_SIZE / 2)
238
240
  face.set_vertex(3, CUBE_SIZE / 2, CUBE_SIZE / 2, CUBE_SIZE / 2)
239
241
  CIRCLE_RES.times do |i|
240
- angle = TAU * i / CIRCLE_RES
241
242
  x = CUBE_SIZE / 2
242
- y = CIRCLE_RAD * sin(angle)
243
- z = CIRCLE_RAD * cos(angle)
243
+ y = sine[i]
244
+ z = cosine[i]
244
245
  face.set_vertex(4 + i, x, y, z)
245
246
  end
246
247
 
@@ -251,10 +252,9 @@ def restore_cube
251
252
  face.set_vertex(2, -CUBE_SIZE / 2, CUBE_SIZE / 2, CUBE_SIZE / 2)
252
253
  face.set_vertex(3, -CUBE_SIZE / 2, CUBE_SIZE / 2, -CUBE_SIZE / 2)
253
254
  CIRCLE_RES.times do |i|
254
- angle = TAU * i / CIRCLE_RES
255
255
  x = -CUBE_SIZE / 2
256
- y = CIRCLE_RAD * sin(angle)
257
- z = CIRCLE_RAD * cos(angle)
256
+ y = sine[i]
257
+ z = cosine[i]
258
258
  face.set_vertex(4 + i, x, y, z)
259
259
  end
260
260
 
@@ -265,10 +265,9 @@ def restore_cube
265
265
  face.set_vertex(2, CUBE_SIZE / 2, CUBE_SIZE / 2, -CUBE_SIZE / 2)
266
266
  face.set_vertex(3, -CUBE_SIZE / 2, CUBE_SIZE / 2, -CUBE_SIZE / 2)
267
267
  CIRCLE_RES.times do |i|
268
- angle = TAU * i / CIRCLE_RES
269
- x = CIRCLE_RAD * sin(angle)
268
+ x = sine[i]
270
269
  y = CUBE_SIZE / 2
271
- z = CIRCLE_RAD * cos(angle)
270
+ z = cosine[i]
272
271
  face.set_vertex(4 + i, x, y, z)
273
272
  end
274
273
 
@@ -279,10 +278,9 @@ def restore_cube
279
278
  face.set_vertex(2, -CUBE_SIZE / 2, -CUBE_SIZE / 2, -CUBE_SIZE / 2)
280
279
  face.set_vertex(3, CUBE_SIZE / 2, -CUBE_SIZE / 2, -CUBE_SIZE / 2)
281
280
  CIRCLE_RES.times do |i|
282
- angle = TAU * i / CIRCLE_RES
283
- x = CIRCLE_RAD * sin(angle)
281
+ x = sine[i]
284
282
  y = -CUBE_SIZE / 2
285
- z = CIRCLE_RAD * cos(angle)
283
+ z = cosine[i]
286
284
  face.set_vertex(4 + i, x, y, z)
287
285
  end
288
286
  end