ruby-processing 2.4.4 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
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,6 +1,6 @@
1
1
  ########################
2
- # NB: Slow to get going
3
- # but, performs Ok after
2
+ # NB: Bit slow to get going
3
+ # but, performs Ok after
4
4
  ########################
5
5
 
6
6
  BOX_SIZE = 20
@@ -16,15 +16,15 @@ def setup
16
16
  @fcount = 0
17
17
  @lastm = 0
18
18
  no_smooth
19
- no_stroke
20
- @grid = create_shape(GROUP)
21
- # Build grid using multiple translations
19
+ no_stroke
20
+ @grid = create_shape(GROUP)
21
+ # Build grid using multiple translations
22
22
  (-(DEPTH/2 + MARGIN) ... (DEPTH/2 - MARGIN)).step(BOX_SIZE) do |i|
23
23
  (-(height + MARGIN) ... (height - MARGIN)).step(BOX_SIZE) do |j|
24
24
  (-(width + MARGIN) ... (width - MARGIN)).step(BOX_SIZE) do |k|
25
- # Base fill color on counter values, abs function
25
+ # Base fill color on counter values, abs function
26
26
  # ensures values stay within legal range
27
- @box_fill = color(i.abs.to_i, j.abs.to_i, k.abs.to_i, 50)
27
+ @box_fill = color(i.abs.to_i, j.abs.to_i, k.abs.to_i, 50)
28
28
  cube = create_shape(BOX, BOX_SIZE.to_f, BOX_SIZE.to_f, BOX_SIZE.to_f)
29
29
  cube.set_fill(box_fill)
30
30
  cube.translate(k, j, i)
@@ -35,24 +35,24 @@ def setup
35
35
  end
36
36
 
37
37
  def draw
38
- background(255)
39
- hint(DISABLE_DEPTH_TEST)
38
+ background(255)
39
+ hint(DISABLE_DEPTH_TEST)
40
40
  # Center and spin grid
41
41
  push_matrix()
42
42
  translate(width/2, height/2, -DEPTH)
43
43
  rotate_y(frame_count * 0.01)
44
44
  rotate_x(frame_count * 0.01)
45
45
  shape(grid)
46
- pop_matrix()
47
- hint(ENABLE_DEPTH_TEST)
46
+ pop_matrix()
47
+ hint(ENABLE_DEPTH_TEST)
48
48
  @fcount += 1
49
49
  m = millis()
50
- if (m - lastm > 1000 * FINT)
50
+ if (m - lastm > 1000 * FINT)
51
51
  @frate = fcount / FINT
52
52
  @fcount = 0
53
53
  @lastm = m
54
- puts("fps: #{frate}")
55
- end
54
+ puts("fps: #{frate}")
55
+ end
56
56
  fill(0)
57
57
  text("fps: #{frate}", 10, 20)
58
58
  end
@@ -1,13 +1,13 @@
1
1
  #
2
2
  # Esfera
3
- # by David Pena.
3
+ # by David Pena.
4
4
  # Somewhat re-factored for ruby-processing
5
5
  # by Martin Prout
6
- # Distribucion aleatoria uniforme sobre la superficie de una esfera.
6
+ # Distribucion aleatoria uniforme sobre la superficie de una esfera.
7
7
  #
8
+ load_library :vecmath
8
9
 
9
-
10
- QUANTITY = 16000
10
+ QUANTITY = 16000
11
11
 
12
12
  attr_reader :orb, :phi, :radius, :rx, :ry
13
13
 
@@ -19,26 +19,20 @@ java_alias :stroke_float_float, :stroke, [Java::float, Java::float]
19
19
 
20
20
  def setup
21
21
  size(800, 600, P3D)
22
+ ArcBall.init(self, width / 2.0, height / 2.0)
22
23
  @rx = 0
23
24
  @ry =0
24
25
  no_smooth
25
26
  @radius = height/3.5
26
27
  @orb = HairyOrb.new(self, radius)
27
28
  QUANTITY.times do
28
- orb << HairFactory.create_hair(radius)
29
+ orb << create_hair(radius)
29
30
  end
30
31
  noise_detail(3)
31
32
  end
32
33
 
33
34
  def draw
34
35
  background_int(0)
35
- translate(width/2,height/2)
36
- rxp = ((mouse_x - (width/2))*0.005)
37
- ryp = ((mouse_y - (height/2))*0.005)
38
- @rx = (rx*0.9)+(rxp*0.1)
39
- @ry = (ry*0.9)+(ryp*0.1)
40
- rotate_y(rx)
41
- rotate_x(ry)
42
36
  fill_int 0
43
37
  no_stroke
44
38
  sphere(radius)
@@ -48,21 +42,30 @@ def draw
48
42
  end
49
43
  end
50
44
 
51
- class HairyOrb
45
+ def create_hair radius
46
+ z = rand(-radius .. radius)
47
+ phi = rand(0 .. TAU)
48
+ len = rand(1.15 .. 1.2)
49
+ theta = Math.asin(z / radius)
50
+ Hair.new(z, phi, len, theta)
51
+ end
52
+
53
+ require 'forwardable'
54
+
55
+ class HairyOrb
52
56
  extend Enumerable
57
+ extend Forwardable
58
+ def_delegators(:@hairs, :each, :<<)
59
+
53
60
  attr_reader :app, :hairs, :radius
54
-
61
+
55
62
  def initialize app, radius
56
63
  @app, @radius = app, radius
57
- @hairs = []
64
+ @hairs = []
58
65
  end
59
-
60
- def << item
61
- hairs << item
62
- end
63
-
64
- def render
65
- hairs.each do |hair|
66
+
67
+ def render
68
+ self.each do |hair|
66
69
  off = (app.noise(app.millis() * 0.0005, sin(hair.phi)) - 0.5) * 0.3
67
70
  offb = (app.noise(app.millis() * 0.0007, sin(hair.z) * 0.01) - 0.5) * 0.3
68
71
  thetaff = hair.theta + off
@@ -83,23 +86,8 @@ class HairyOrb
83
86
  app.stroke_float_float(200, 150)
84
87
  app.vertex(xb, yb, zb)
85
88
  app.end_shape()
86
- end
89
+ end
87
90
  end
88
91
  end
89
92
 
90
- class HairFactory
91
- def self.create_hair radius
92
- z = rand(-radius .. radius)
93
- phi = rand * Math::PI * 2
94
- len = rand(1.15 .. 1.2)
95
- theta = Math.asin(z / radius)
96
- return Hair.new(z, phi, len, theta)
97
- end
98
- end
99
-
100
- class Hair
101
- attr_reader :z, :phi, :len, :theta
102
- def initialize z, phi, len, theta
103
- @z, @phi, @len, @theta = z, phi, len, theta
104
- end
105
- end
93
+ Hair = Struct.new(:z, :phi, :len, :theta )
@@ -3,7 +3,7 @@ def setup
3
3
  fill(0)
4
4
  end
5
5
 
6
- def draw
6
+ def draw
7
7
  background(255)
8
8
  (0 .. 10000).each do
9
9
  x = rand(width)
@@ -0,0 +1,44 @@
1
+ # The current time can be read with the second(), minute(), and hour()
2
+ # functions. In this example, DegLut.sin() and DegLut.cos() values are used to
3
+ # set the position of the hands, perfect for degree precision Lookup Table.
4
+ load_library :fastmath
5
+
6
+ def setup
7
+ size 200, 200
8
+ stroke 255
9
+ smooth 8
10
+ end
11
+
12
+ def draw
13
+ background 0
14
+ fill 80
15
+ no_stroke
16
+ # adj factor to map 0-60 to 0-360 (seconds/minutes) & 0-12 to 0-360 (hours)
17
+ # since angles for DegLut.sin() and DegLut.cos() start at 3 o'clock we
18
+ # subtract 90 degrees to make them start at the top.
19
+ clock_x = lambda do |val, adj, length|
20
+ DegLut.cos((val * adj).to_i - 90) * length + width / 2
21
+ end
22
+ clock_y = lambda do |val, adj, length|
23
+ DegLut.sin((val * adj).to_i - 90) * length + height / 2
24
+ end
25
+ ellipse 100, 100, 160, 160
26
+ stroke 220
27
+ stroke_weight 6
28
+ line(100, 100, clock_x.call(hour % 12 + (minute / 60.0), 30, 50),
29
+ clock_y.call(hour % 12 + (minute / 60.0), 30, 50))
30
+ stroke_weight 3
31
+ line(100, 100, clock_x.call(minute + (second / 60.0), 6, 60),
32
+ clock_y.call(minute + (second / 60.0), 6, 60))
33
+ stroke 255, 0, 0
34
+ stroke_weight 1
35
+ line(100, 100, clock_x.call(second, 6, 72), clock_y.call(second, 6, 72))
36
+ # Draw the minute ticks
37
+ stroke_weight 2
38
+ stroke 255
39
+ (0..360).step(6) do |a|
40
+ x = 100 + DegLut.cos(a) * 72
41
+ y = 100 + DegLut.sin(a) * 72
42
+ point x, y
43
+ end
44
+ end
@@ -2,7 +2,7 @@
2
2
  # Geometry
3
3
  # by Marius Watz.
4
4
  #
5
- load_library 'pdf'
5
+ load_libraries :pdf, :fastmath
6
6
  include_package 'processing.pdf'
7
7
 
8
8
  attr_reader :num, :pt, :style, :dosave
@@ -18,37 +18,38 @@ def setup
18
18
  # Set up arc shapes
19
19
  index = 0
20
20
  (0 ... num).each do |i|
21
- pt.push(rand(TWO_PI)) # Random X axis rotation
22
- pt.push(rand(TWO_PI)) # Random Y axis rotation
21
+ pt << rand(TAU) # Random X axis rotation
22
+ pt << rand(TAU) # Random Y axis rotation
23
23
 
24
- pt.push(rand(60 .. 80)) # Short to quarter-circle arcs
24
+ pt << rand(60 .. 80) # Short to quarter-circle arcs
25
25
  if (rand(100)>90)
26
26
  pt[pt.length - 1] = rand(8 .. 27) * 10
27
27
  end
28
- pt.push(rand(2 .. 50) * 5) # Radius. Space them out nicely
28
+ pt << rand(2 .. 50) * 5 # Radius. Space them out nicely
29
29
 
30
- pt.push(rand(4 .. 32)) # Width of band
30
+ pt << rand(4 .. 32) # Width of band
31
31
  if (rand(100) > 90)
32
32
  pt[pt.length - 1] = rand(40 .. 60) # Width of band
33
33
  end
34
34
 
35
- pt.push(rand(0.005 .. 0.0334))# Speed of rotation
35
+ pt << rand(0.005 .. 0.0334)# Speed of rotation
36
36
 
37
37
  # get colors
38
38
  prob = rand(100)
39
- if (prob < 30)
39
+ case prob
40
+ when (0 .. 30)
40
41
  style[i*2] = color_blended(rand, 255,0,100, 255,0,0, 210)
41
- elsif(prob < 70)
42
+ when (30 .. 70)
42
43
  style[i*2] = color_blended(rand, 0,153,255, 170,225,255, 210)
43
- elsif(prob<90)
44
+ when (70 .. 90)
44
45
  style[i*2] = color_blended(rand, 200,255,0, 150,255,0, 210)
45
46
  else
46
47
  style[i*2] = color(255,255,255, 220)
47
48
  end
48
-
49
- if (prob < 50)
49
+ case prob
50
+ when (0 .. 50)
50
51
  style[i*2] = color_blended(rand, 200,255,0, 50,120,0, 210)
51
- elsif(prob < 90)
52
+ when (50 .. 90)
52
53
  style[i*2] = color_blended(rand, 255,100,0, 255,255,0, 210)
53
54
  else
54
55
  style[i*2] = color(255, 255, 255, 220)
@@ -78,13 +79,14 @@ def draw
78
79
  rotate_x(pt[index])
79
80
  rotate_y(pt[index + 1])
80
81
  index += 2
81
- if (style[i*2+1] == 0)
82
+ case (style[i*2+1])
83
+ when 0
82
84
  stroke(style[i*2])
83
85
  no_fill
84
86
  stroke_weight(1)
85
87
  arc_line(0,0, pt[index],pt[index + 1],pt[index + 2])
86
88
  index += 3
87
- elsif (style[i*2+1] == 1)
89
+ when 1
88
90
  fill(style[i*2])
89
91
  no_stroke
90
92
  arc_line_bars(0,0, pt[index],pt[index + 1],pt[index + 2])
@@ -113,7 +115,7 @@ def color_blended(fract, r, g, b, r2, g2, b2, a)
113
115
  r2 = (r2 - r)
114
116
  g2 = (g2 - g)
115
117
  b2 = (b2 - b)
116
- return color(r + r2 * fract, g + g2 * fract, b + b2 * fract, a)
118
+ color(r + r2 * fract, g + g2 * fract, b + b2 * fract, a)
117
119
  end
118
120
 
119
121
 
@@ -124,7 +126,7 @@ def arc_line(x, y, deg, rad, w)
124
126
  (0 ... numlines).each do
125
127
  begin_shape
126
128
  (0 ... a).each do |i|
127
- vertex(cos(i.radians)*rad+x,sin(i.radians)*rad+y)
129
+ vertex(DegLut.cos(i)*rad+x,DegLut.sin(i)*rad+y)
128
130
  end
129
131
  end_shape
130
132
  rad += 2
@@ -136,21 +138,21 @@ def arc_line_bars(x, y, deg, rad, w)
136
138
  a=(deg < 360)? deg / 16 : 0
137
139
  begin_shape(QUADS)
138
140
  (0 ... a).step(4) do |i|
139
- vertex(cos(i.radians)*(rad)+x,sin(i.radians)*(rad)+y)
140
- vertex(cos(i.radians)*(rad+w)+x,sin(i.radians)*(rad+w)+y)
141
- vertex(cos((i + 2).radians)*(rad+w)+x,sin((i + 2).radians)*(rad+w)+y)
142
- vertex(cos((i + 2).radians)*(rad)+x,sin((i + 2).radians)*(rad)+y)
141
+ vertex(DegLut.cos(i)*(rad)+x,DegLut.sin(i)*(rad)+y)
142
+ vertex(DegLut.cos(i)*(rad+w)+x,DegLut.sin(i)*(rad+w)+y)
143
+ vertex(DegLut.cos((i + 2))*(rad+w)+x,DegLut.sin((i + 2))*(rad+w)+y)
144
+ vertex(DegLut.cos((i + 2))*(rad)+x,DegLut.sin((i + 2))*(rad)+y)
143
145
  end
144
146
  end_shape
145
147
  end
146
148
 
147
149
  # Draw solid arc
148
- def arc(x,y,deg,rad,w)
150
+ def arc(x, y, deg, rad, w)
149
151
  a = (deg < 360)? deg : 0
150
152
  begin_shape(QUAD_STRIP)
151
153
  (0 ... a).each do |i|
152
- vertex(cos(i.radians)*(rad)+x,sin(i.radians)*(rad)+y)
153
- vertex(cos(i.radians)*(rad+w)+x,sin(i.radians)*(rad+w)+y)
154
+ vertex(DegLut.cos(i)*(rad)+x,DegLut.sin(i)*(rad)+y)
155
+ vertex(DegLut.cos(i)*(rad+w)+x,DegLut.sin(i)*(rad+w)+y)
154
156
  end
155
157
  end_shape
156
158
  end
@@ -1,20 +1,20 @@
1
1
  # Simple demo Rakefile to autorun samples in current directory
2
2
  # adjust path to rp5 executable, and or opts as required
3
3
 
4
- SAMPLES_DIR="./"
4
+ SAMPLES_DIR = './'
5
5
 
6
6
  desc 'run demo'
7
- task :default => [:demo]
7
+ task default: [:demo]
8
8
 
9
9
  desc 'demo'
10
10
  task :demo do
11
- samples_list.shuffle.each{|sample| run_sample sample}
11
+ samples_list.shuffle.each{ |sample| run_sample sample }
12
12
  end
13
13
 
14
14
  def samples_list
15
15
  files = []
16
16
  Dir.chdir(SAMPLES_DIR)
17
- Dir.glob("*.rb").each do |file|
17
+ Dir.glob('*.rb').each do |file|
18
18
  files << File.join(SAMPLES_DIR, file)
19
19
  end
20
20
  return files
@@ -22,9 +22,9 @@ end
22
22
 
23
23
  def run_sample(sample_name)
24
24
  puts "Running #{sample_name}...quit to run next sample"
25
- open("|rp5 --nojruby run #{sample_name}", "r") do |io|
25
+ open("|rp5 run #{sample_name}", 'r') do |io|
26
26
  while l = io.gets
27
- puts(l.chop)
27
+ puts(l.chop)
28
28
  end
29
29
  end
30
30
  end
@@ -0,0 +1,23 @@
1
+ load_library :vecmath
2
+
3
+ ############################
4
+ # Use mouse drag to rotate
5
+ # the arcball. Use mousewheel
6
+ # to zoom. Hold down x, y, z
7
+ # to constrain rotation axis.
8
+ ############################
9
+
10
+ def setup
11
+ size(600, 600, P3D)
12
+ smooth(16)
13
+ ArcBall.init(self, 300, 300)
14
+ fill 180
15
+ end
16
+
17
+ def draw
18
+ background(50)
19
+ box(300, 300, 300)
20
+ end
21
+
22
+
23
+
@@ -0,0 +1,23 @@
1
+ load_library :vecmath
2
+
3
+ ############################
4
+ # Use mouse drag to rotate
5
+ # the arcball. Use mousewheel
6
+ # to zoom. Hold down x, y, z
7
+ # to constrain rotation axis.
8
+ ############################
9
+
10
+ def setup
11
+ size(600, 600, P3D)
12
+ smooth(16)
13
+ ArcBall.init(self, 300, 300, 250)
14
+ fill 180
15
+ end
16
+
17
+ def draw
18
+ background(50)
19
+ box(300, 300, 300)
20
+ end
21
+
22
+
23
+
@@ -0,0 +1,29 @@
1
+ load_library :vecmath
2
+
3
+ attr_reader :my_cube
4
+
5
+ def setup
6
+ size(600, 600, P3D)
7
+ smooth(16)
8
+ ArcBall.init(self)
9
+ @my_cube = create_shape(BOX, 400, 400, 400)
10
+ my_cube.set_fill(color(100, 10, 100))
11
+
12
+ end
13
+
14
+ def draw
15
+ background(50, 50, 100)
16
+ define_lights
17
+ lights
18
+ stroke(0)
19
+ shape(my_cube)
20
+ end
21
+
22
+ def define_lights
23
+ ambient(20, 20, 20)
24
+ ambient_light(50, 50, 50)
25
+ point_light(30, 30, 30, 200, -150, 0)
26
+ directional_light(0, 30, 50, 1, 0, 0)
27
+ spot_light(30, 30, 30, 0, 40, 200, 0, -0.5, -0.5, PI / 2, 2)
28
+ end
29
+