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
@@ -0,0 +1,52 @@
1
+ ############################################
2
+ # mesh_to_vbo.rb
3
+ # a ruby library to convert toxi.mesh object
4
+ # to vbo (PShape) written by Martin Prout
5
+ # make use of Processing::Proxy mixin
6
+ ############################################
7
+ class MeshToVBO
8
+ include Processing::Proxy
9
+
10
+ attr_reader :parent
11
+
12
+ def initialize(parent)
13
+ @parent = parent
14
+ end
15
+
16
+ def meshToVBO(mesh: nil, smooth: false)
17
+ retained = parent.createShape()
18
+ retained.begin_shape(PShape::TRIANGLES)
19
+ if (smooth)
20
+ mesh.computeVertexNormals()
21
+ mesh.getFaces.each do |f|
22
+ retained.normal(f.a.normal.x, f.a.normal.y, f.a.normal.z)
23
+ retained.vertex(f.a.x, f.a.y, f.a.z)
24
+ retained.normal(f.b.normal.x, f.b.normal.y, f.b.normal.z)
25
+ retained.vertex(f.b.x, f.b.y, f.b.z)
26
+ retained.normal(f.c.normal.x, f.c.normal.y, f.c.normal.z)
27
+ retained.vertex(f.c.x, f.c.y, f.c.z)
28
+ end
29
+ else
30
+ mesh.getFaces.each do |f|
31
+ retained.normal(f.normal.x, f.normal.y, f.normal.z)
32
+ retained.vertex(f.a.x, f.a.y, f.a.z)
33
+ retained.vertex(f.b.x, f.b.y, f.b.z)
34
+ retained.vertex(f.c.x, f.c.y, f.c.z)
35
+ end
36
+ end
37
+ retained.end_shape()
38
+ return retained
39
+ end
40
+
41
+ # variant
42
+ # input array of meshes, output an array of shapes
43
+ def meshToRetained(mesh_array: [], smooth: false)
44
+ rshapes = []
45
+ (0 ... mesh.length).each do |i|
46
+ rshapes.push(meshToVBO(mesh: mesh[i], smooth: smth))
47
+ end
48
+ return rshapes
49
+ end
50
+ end
51
+
52
+
@@ -5,7 +5,7 @@
5
5
  #
6
6
  # (c) 2012 Karsten Schmidt / LGPL2 licensed
7
7
  #
8
- load_libraries 'toxiclibscore', 'toxiclibs_p5', 'colorutils'
8
+ load_libraries :toxiclibscore, :toxiclibs_p5, :colorutils, :vecmath
9
9
 
10
10
  module Toxi
11
11
  include_package 'toxi.geom'
@@ -19,20 +19,16 @@ attr_reader :gfx, :positions
19
19
 
20
20
  def setup
21
21
  size(640,480,P3D)
22
+ ArcBall.init(self)
22
23
  @gfx = Toxi::ToxiclibsSupport.new(self)
23
- @positions = []
24
24
  # compute mesh positions on circle in XZ plane
25
- (Toxi::Circle.new(200).toPolygon2D(8)).each do |p|
26
- positions << p.to3DXZ
27
- end
25
+ @positions = (Toxi::Circle.new(200).toPolygon2D(8)).map{ |p| p.to3DXZ}
28
26
  end
29
27
 
30
28
  def draw
31
29
  background(51)
32
30
  lights
33
31
  no_stroke
34
- translate(width/2,height/2,0)
35
- rotate_x(-PI/6)
36
32
  # create manual focal point in XY plane
37
33
  focus = Toxi::Vec3D.new((mouse_x - width/2), (mouse_y - height/2), 0)
38
34
  # create mesh prototype to draw at all generated positions
@@ -40,16 +36,13 @@ def draw
40
36
  m = Toxi::AABB.new(25).to_mesh
41
37
  # draw focus
42
38
  gfx.box(Toxi::AABB.new(focus, 5))
43
- positions.each do |p|
44
- # align the positive z-axis of mesh to point at focus
45
- # mesh needs to be located at world origin for it to work correctly
46
- # only once rotated, move it to actual position
47
- gfx.mesh(m.copy.pointTowards(focus.sub(p), Toxi::Vec3D::Z_AXIS).translate(p))
48
- end
39
+ # align the positive z-axis of mesh to point at focus
40
+ # mesh needs to be located at world origin for it to work correctly
41
+ # only once rotated, move it to actual position
42
+ positions.map {|p| gfx.mesh(m.copy.pointTowards(focus.sub(p), Toxi::Vec3D::Z_AXIS).translate(p))}
43
+
49
44
  # draw connections from mesh centers to focal point
50
45
  stroke(0,255,255)
51
- positions.each do |p|
52
- gfx.line(p, focus)
53
- end
46
+ positions.map {|p| gfx.line(p, focus)}
54
47
  end
55
48
 
@@ -29,7 +29,7 @@ def create_wheel( x, y, value_shift )
29
29
  rot_adjust = (360.0 / segs / 2.0) * PI / 180
30
30
  radius = 170.0
31
31
  seg_width = radius / steps
32
- interval = TWO_PI / segs
32
+ interval = TAU / segs
33
33
 
34
34
  case value_shift
35
35
  when :shade
@@ -35,9 +35,9 @@ def draw
35
35
  end
36
36
 
37
37
  def polygon(x, y, radius, npoints)
38
- angle = TWO_PI / npoints
38
+ angle = TAU / npoints
39
39
  begin_shape
40
- (0 .. TWO_PI).step(angle) do |a|
40
+ (0 .. TAU).step(angle) do |a|
41
41
  sx = x + cos(a) * radius
42
42
  sy = y + sin(a) * radius
43
43
  vertex(sx, sy)
@@ -39,8 +39,8 @@ def draw
39
39
  background 1
40
40
  push_matrix
41
41
  translate width/2, height/2, -30
42
- @new_xmag = mouse_x.to_f / width * TWO_PI
43
- @new_ymag = mouse_y.to_f / height * TWO_PI
42
+ @new_xmag = mouse_x.to_f / width * TAU
43
+ @new_ymag = mouse_y.to_f / height * TAU
44
44
  diff = @xmag - @new_xmag
45
45
  @xmag -= diff / 4 if diff.abs > 0.01
46
46
  diff = @ymag - @new_ymag
@@ -18,6 +18,6 @@ ellipse 252, 144, 72, 72
18
18
  fill 204
19
19
  triangle 288, 18, 351, 360, 288, 360
20
20
  fill(255)
21
- arc(479, 300, 280, 280, PI, TWO_PI)
21
+ arc(479, 300, 280, 280, PI, TAU)
22
22
 
23
23
 
@@ -33,10 +33,10 @@ def draw
33
33
  end
34
34
 
35
35
  def star(x, y, radius1, radius2, npoints)
36
- angle = TWO_PI / npoints
36
+ angle = TAU / npoints
37
37
  half_angle = angle/2.0
38
38
  begin_shape
39
- (0 .. TWO_PI).step(angle) do |a|
39
+ (0 .. TAU).step(angle) do |a|
40
40
  sx = x + cos(a) * radius2
41
41
  sy = y + sin(a) * radius2
42
42
  vertex(sx, sy)
@@ -1,40 +1,45 @@
1
1
  # The current time can be read with the second(), minute(),
2
2
  # and hour() functions. In this example, sin() and cos() values
3
3
  # are used to set the position of the hands.
4
-
4
+ load_library :fastmath
5
5
 
6
6
  def setup
7
7
  size 200, 200
8
8
  stroke 255
9
- smooth
9
+ smooth 4
10
10
  end
11
11
 
12
12
  def draw
13
13
  background 0
14
14
  fill 80
15
- no_stroke
16
-
17
- # Angles for sin() and cos() start at 3 o'clock;
18
- # subtract HALF_PI to make them start at the top
19
- ellipse 100, 100, 160, 160
20
-
21
- s = map( second, 0, 60, 0, TWO_PI) - HALF_PI
22
- m = map( minute + norm( second, 0, 60 ), 0, 60, 0, TWO_PI ) - HALF_PI
23
- h = map( hour + norm( minute, 0, 60 ), 0, 24, 0, TWO_PI * 2 ) - HALF_PI
15
+ no_stroke
16
+
17
+ ellipse 100, 100, 160, 160
24
18
 
25
19
  stroke 255
26
20
  stroke_weight 1
27
- line( 100, 100, cos(s)*72 + 100, sin(s)*72 + 100 )
21
+ line( 100, 100, calc_hand_x(second, 0, 72, 100), calc_hand_y(second, 0, 72, 100) )
28
22
  stroke_weight 2
29
- line( 100, 100, cos(m)*60 + 100, sin(m)*60 + 100 )
23
+ line( 100, 100, calc_hand_x(minute, second, 60, 100), calc_hand_y(minute, second, 60, 100) )
30
24
  stroke_weight 4
31
- line( 100, 100, cos(h)*50 + 100, sin(h)*50 + 100 )
25
+ line( 100, 100, calc_hand_x(hour, minute, 50, 100), calc_hand_y(hour, minute, 50, 100) )
32
26
 
33
27
  # Draw the minute ticks
34
28
  stroke_weight 2
35
29
  (0..360).step(6) do |a|
36
- x = 100 + cos( a.radians ) * 72
37
- y = 100 + sin( a.radians ) * 72
30
+ x = 100 + DegLut.cos(a) * 72
31
+ y = 100 + DegLut.sin(a) * 72
38
32
  point x, y
39
33
  end
40
34
  end
35
+
36
+ # Angles for sin() and cos() start at 3 o'clock;
37
+ # subtract 90 degrees to make them start at the top
38
+
39
+ def calc_hand_x(time, time_bit, length, origin)
40
+ DegLut.cos(time * 6 + time_bit / 10 - 90) * length + origin
41
+ end
42
+
43
+ def calc_hand_y(time, time_bit, length, origin)
44
+ DegLut.sin(time * 6 + time_bit / 10 - 90) * length + origin
45
+ end
@@ -9,14 +9,14 @@
9
9
  #
10
10
 
11
11
  NUM = 60
12
- X = 0
13
- Y = 1
14
-
12
+
15
13
  attr_reader :pos
16
14
 
15
+ Vec = Struct.new(:x, :y)
16
+
17
17
  def setup
18
18
  size(640, 360)
19
- @pos = Array.new(NUM, Array.new(2, 0)) # initialize a nested array
19
+ @pos = Array.new(NUM, Vec.new(0, 0)) # initialize a array of Vec Struct
20
20
  smooth(4)
21
21
  noStroke()
22
22
  fill(255, 153)
@@ -28,11 +28,11 @@ def draw
28
28
  # Cycle through the array, using a different entry on each frame.
29
29
  # Using modulo (%) like this is faster than moving all the values over.
30
30
  which = frame_count % NUM
31
- pos[which] = [mouse_x, mouse_y]
31
+ pos[which] = Vec.new(mouse_x, mouse_y)
32
32
 
33
33
  (1 .. NUM).each do |i|
34
34
  # which + 1 is the smallest (the oldest in the array)
35
35
  idx = (which + i) % NUM
36
- ellipse(pos[idx][X], pos[idx][Y], i, i)
36
+ ellipse(pos[idx].x, pos[idx].y, i, i)
37
37
  end
38
38
  end
@@ -18,7 +18,7 @@ def setup
18
18
  @max_waves.times do |i|
19
19
  amplitude << rand(10 .. 30)
20
20
  period = rand(100 .. 300) # How many pixels before the wave repeats
21
- dx << (TWO_PI / period) * @x_spacing
21
+ dx << (TAU / period) * @x_spacing
22
22
  end
23
23
 
24
24
  frame_rate 30
@@ -26,10 +26,10 @@ def draw
26
26
  rotate angle_rot - 45
27
27
  ellipse(-116, 0, @diameter, @diameter)
28
28
  pop_matrix
29
- angle_rot += TWO_PI/5
29
+ angle_rot += TAU/5
30
30
  }
31
31
  @diameter = 34 * sin( @angle ) + 168
32
32
  @angle += 0.02
33
- #@angle = 0.0 if @angle > TWO_PI
33
+ #@angle = 0.0 if @angle > TAU
34
34
  end
35
35
 
@@ -2,7 +2,7 @@
2
2
  # Sine Cosine.
3
3
  #
4
4
  # Linear movement with sin() and cos().
5
- # Numbers between 0 and PI*2 (TWO_PI which angles roughly 6.28)
5
+ # Numbers between 0 and PI*2 (TAU which angles roughly 6.28)
6
6
  # are put into these functions and numbers between -1 and 1 are
7
7
  # returned. These values are then scaled to produce larger movements.
8
8
  # note only angle1 angle2 need scope outside draw loop
@@ -11,7 +11,7 @@ def setup
11
11
  @w = width + 16
12
12
  @period = 500.0
13
13
  @x_spacing = 8
14
- @dx = (TWO_PI / @period) * @x_spacing
14
+ @dx = (TAU / @period) * @x_spacing
15
15
  @y_values = []
16
16
  @theta = 0.0
17
17
  @amplitude = 75.0
@@ -4,6 +4,8 @@
4
4
  # programming terminology, one class can inherit fields and methods from another.
5
5
  # An object that inherits from another is called a subclass, and the object it
6
6
  # inherits from is called a superclass. A subclass extends the superclass.
7
+ # see also inheritance_two for the use of hash args and inheritance that
8
+ # avoids the inherited class call to super
7
9
 
8
10
 
9
11
  def setup
@@ -0,0 +1,88 @@
1
+ # Inheritance
2
+ #
3
+ # A class can be defined using another class as a foundation. In object-oriented
4
+ # programming terminology, one class can inherit fields and methods from another.
5
+ # An object that inherits from another is called a subclass, and the object it
6
+ # inherits from is called a superclass. A subclass extends the superclass.
7
+ # NB: note the use of hook means inheriting class does not need to call super
8
+
9
+
10
+ def setup
11
+ size 640, 360
12
+ @arm = SpinArm.new({ x: width/2, y: height/2, s: 0.01 })
13
+ @spots = SpinSpots.new({ x: width/2, y: height/2, s: -0.02, d: 90.0 })
14
+ end
15
+
16
+ def draw
17
+ background 204
18
+ @arm.display
19
+ @spots.display
20
+ end
21
+
22
+ # vvv CLASS SPIN
23
+
24
+ class Spin
25
+
26
+ attr_accessor :x, :y, :speed
27
+ attr_accessor :angle
28
+
29
+ def initialize(args = {})
30
+ @x, @y = args[:x], args[:y]
31
+ @speed = args[:s]
32
+ @angle = args[:angle] || 0.0
33
+ post_initialize(args) # this is the hook
34
+ end
35
+
36
+ def update
37
+ @angle += speed
38
+ end
39
+
40
+ def post_initialize args
41
+ nil
42
+ end
43
+
44
+ end
45
+
46
+ # ^^^ CLASS SPIN
47
+
48
+ # vvv CLASS SPINARM
49
+
50
+ class SpinArm < Spin # inherit from (or "extend") class Spin
51
+ # NB: initialize inherited from Spin class
52
+
53
+ def display
54
+ stroke_weight 1
55
+ stroke 0
56
+ push_matrix
57
+ translate x, y
58
+ update
59
+ rotate angle
60
+ line 0, 0, 165, 0
61
+ pop_matrix
62
+ end
63
+ end
64
+
65
+ # ^^^ CLASS SPINARM
66
+
67
+ # vvv CLASS SPINSPOTS
68
+
69
+ class SpinSpots < Spin
70
+ attr_accessor :dim
71
+
72
+ def post_initialize args
73
+ @dim = args[:d]
74
+ end
75
+
76
+ def display
77
+ no_stroke
78
+ push_matrix
79
+ translate x, y
80
+ update
81
+ rotate angle
82
+ ellipse(-dim/2, 0, dim, dim)
83
+ ellipse(dim/2, 0, dim, dim)
84
+ pop_matrix
85
+ end
86
+ end
87
+
88
+ # ^^^ CLASS SPINSPOTS
@@ -0,0 +1,89 @@
1
+ # Ruby modules, are another way of extending a classes behaviour, the class
2
+ # ParticleSystem includes Enumerable (from ruby core) and our custom Runnable
3
+ # module. Here we use the module Runnable to capture behaviour that can be
4
+ # shared between different classes. Modules are also very useful for wrapping
5
+ # imported classes (wrapped packages can then be called using convenient names).
6
+
7
+ # This example is bit complicated, because Enumerable and Forwardable are used
8
+ # to make the ParticleSystem behave as though it were an Array. This is very
9
+ # convenient and is preferred to ParticleSystem subclassing Array.
10
+
11
+ # Ported from http://processing.org/learning/topics/simpleparticlesystem.html
12
+
13
+
14
+ require 'forwardable'
15
+
16
+ load_library :vecmath
17
+
18
+ attr_reader :ps
19
+
20
+ def setup
21
+ size(640,360)
22
+ @ps = ParticleSystem.new(Vec2D.new(width/2, 50))
23
+ end
24
+
25
+ def draw
26
+ background(0)
27
+ ps.add_particle
28
+ ps.run
29
+ end
30
+
31
+ module Runnable
32
+ def run
33
+ self.reject! { |item| item.lifespan <= 0 }
34
+ self.each { |item| item.run }
35
+ end
36
+ end
37
+
38
+ class ParticleSystem
39
+ extend Forwardable
40
+ def_delegators(:@particle_system, :each, :<<, :reject!)
41
+ include Enumerable
42
+ include Runnable
43
+
44
+ attr_reader :origin
45
+
46
+ def initialize(loc)
47
+ @particle_system = []
48
+ @origin = Vec2D.new(loc.x, loc.y)
49
+ end
50
+
51
+ def add_particle
52
+ self << Particle.new(origin)
53
+ end
54
+
55
+ end
56
+
57
+ # A simple Particle class
58
+
59
+ class Particle
60
+ include Processing::Proxy
61
+
62
+ attr_reader :loc, :vel, :acc, :lifespan
63
+ def initialize(loc)
64
+ @acc = Vec2D.new(0, 0.05)
65
+ @vel = Vec2D.new(rand(-1.0 .. 1), rand(-2.0 .. 0))
66
+ @loc = loc # loc.clone is unecessary in ruby
67
+ @lifespan = 255.0
68
+ end
69
+
70
+ def run
71
+ update
72
+ display
73
+ end
74
+
75
+ # Method to update loc
76
+ def update
77
+ @vel += acc
78
+ @loc += vel
79
+ @lifespan -= 1.0
80
+ end
81
+
82
+ # Method to display
83
+ def display
84
+ stroke(255,lifespan)
85
+ fill(255,lifespan)
86
+ ellipse(loc.x, loc.y, 8, 8)
87
+ end
88
+
89
+ end