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
  #
2
2
  # Regular Expression example
3
- # by Martin Prout.
4
- #
3
+ # by Martin Prout.
4
+ #
5
5
  # This uses ruby scan
6
6
  #
7
7
  # Here we'll load the raw HTML from a URL and search for web-links
@@ -11,11 +11,11 @@ attr_reader :links, :url
11
11
 
12
12
  def setup
13
13
  size(360, 480)
14
- @url = "http://processing.org"
14
+ @url = 'http://processing.org'
15
15
  # Load the links
16
16
  @links = load_links(url)
17
17
  links.uniq! # get rid of the duplicates
18
- text_font(create_font("Georgia", 16))
18
+ text_font(create_font('Georgia', 16))
19
19
  end
20
20
 
21
21
  def draw
@@ -43,5 +43,4 @@ def load_links(s)
43
43
  [\w=]*
44
44
  )?
45
45
  /ix)
46
- end
47
-
46
+ end
@@ -1,11 +1,11 @@
1
- #
1
+ #
2
2
  # Thread function example
3
- # by Martin Prout (after a Dan Schiffman vanilla processing version).
4
- #
3
+ # by Martin Prout (after a Dan Schiffman vanilla processing version).
4
+ #
5
5
  # This example demonstrates how to use Thread.new to spawn
6
6
  # a process that happens outside of the main animation thread.
7
7
  #
8
- # When Thread.new is called, the draw() loop will continue while
8
+ # When Thread.new is called, the draw loop will continue while
9
9
  # the code inside the block passed to the thread will operate
10
10
  # in the background.
11
11
  #
@@ -15,19 +15,19 @@
15
15
  # This sketch will load data from all of these URLs in a separate thread
16
16
 
17
17
  URLS = [
18
- "http://processing.org",
19
- "http://www.processing.org/exhibition/",
20
- "http://www.processing.org/reference/",
21
- "http://www.processing.org/reference/libraries",
22
- "http://www.processing.org/reference/tools",
23
- "http://www.processing.org/reference/environment",
24
- "http://www.processing.org/learning/",
25
- "http://www.processing.org/learning/basics/",
26
- "http://www.processing.org/learning/topics/",
27
- "http://www.processing.org/learning/gettingstarted/",
28
- "http://www.processing.org/download/",
29
- "http://www.processing.org/shop/",
30
- "http://www.processing.org/about/"
18
+ 'http://processing.org',
19
+ 'http://www.processing.org/exhibition/',
20
+ 'http://www.processing.org/reference/',
21
+ 'http://www.processing.org/reference/libraries',
22
+ 'http://www.processing.org/reference/tools',
23
+ 'http://www.processing.org/reference/environment',
24
+ 'http://www.processing.org/learning/',
25
+ 'http://www.processing.org/learning/basics/',
26
+ 'http://www.processing.org/learning/topics/',
27
+ 'http://www.processing.org/learning/gettingstarted/',
28
+ 'http://www.processing.org/download/',
29
+ 'http://www.processing.org/shop/',
30
+ 'http://www.processing.org/about/'
31
31
  ]
32
32
 
33
33
 
@@ -42,14 +42,14 @@ end
42
42
 
43
43
  def draw
44
44
  background(0)
45
-
46
- # If we're not finished draw a "loading bar"
45
+
46
+ # If we're not finished draw a 'loading bar'
47
47
  # This is so that we can see the progress of the thread
48
48
  # This would not be necessary in a sketch where you wanted to load data in the background
49
- # and hide this from the user, allowing the draw() loop to simply continue
49
+ # and hide this from the user, allowing the draw loop to simply continue
50
50
  if (!finished)
51
51
  stroke(255)
52
- no_fill()
52
+ no_fill
53
53
  rect(width/2-150, height/2, 300, 10)
54
54
  fill(255)
55
55
  # The size of the rectangle is mapped to the percentage completed
@@ -58,29 +58,29 @@ def draw
58
58
  text_size(16)
59
59
  text_align(CENTER)
60
60
  fill(255)
61
- text("Loading", width/2, height/2+30)
61
+ text('Loading', width/2, height/2+30)
62
62
  else
63
63
  # The thread is complete!
64
64
  text_align(CENTER)
65
65
  text_size(24)
66
66
  fill(255)
67
- text("Finished loading. Click the mouse to load again.", width/2, height/2)
67
+ text('Finished loading. Click the mouse to load again.', width/2, height/2)
68
68
  end
69
69
  end
70
70
 
71
71
  def load_data
72
- Thread.new {
72
+ Thread.new {
73
73
  # The thread is not completed
74
74
  @finished = false
75
75
  @percent = 0
76
76
  # Reset the data to empty
77
- @all_data = ""
77
+ @all_data = ''
78
78
  URLS.each_with_index do |url, i|
79
79
  lines = load_strings(url)
80
80
  all_txt = lines.join(' ')
81
81
  words = all_txt.scan(/\w+/)
82
82
  words.each do |word|
83
- word.strip!
83
+ word.strip!
84
84
  word.downcase!
85
85
  end
86
86
  words.sort!
@@ -92,5 +92,5 @@ def load_data
92
92
  end
93
93
 
94
94
  def mouse_pressed # guard against calling load_data when running
95
- load_data unless !finished
95
+ load_data unless !finished
96
96
  end
@@ -16,7 +16,8 @@ def setup
16
16
  @curr = 0
17
17
  thread do # supply a block in ruby-processing rather than use reflection
18
18
  FRAMES.times do |i|
19
- frames << load_image("a#{nf(i, 3)} copy.jpg")
19
+ frames << load_image("a#{i.to_s.rjust(3, "0")} copy.jpg") # ruby syntax
20
+ #frames << load_image("a#{nf(i, 3)} copy.jpg") # processing function nf
20
21
  @curr = i
21
22
  delay(75) #just slows down this thread - the main draw cycle is unaffected...
22
23
  end
@@ -30,7 +31,7 @@ end
30
31
 
31
32
  def draw
32
33
  if (done_loading)
33
- background(0)
34
+ background(0)
34
35
  image(frames[curr], 0, 0)
35
36
  @curr += 1
36
37
  if (curr > 115)
@@ -1,24 +1,26 @@
1
1
  #
2
2
  # After a HashMap example
3
- # by Daniel Shiffman.
4
- #
5
- # This example demonstrates how to use a Hash to store
6
- # a collection of objects referenced by a key. This is much like an array,
3
+ # by Daniel Shiffman.
4
+ #
5
+ # This example demonstrates how to use a Hash to store
6
+ # a collection of objects referenced by a key. This is much like an array,
7
7
  # only instead of accessing elements with a numeric index, we use a String.
8
8
  # If you are familiar with associative arrays from other languages,
9
9
  # this is the same idea.
10
10
  #
11
11
  # The Processing classes IntHash, FloatHash, and StringHash offer a simple
12
- # way of pairing Strings with numbers or other Strings. But are probably of
12
+ # way of pairing Strings with numbers or other Strings. But are probably of
13
13
  # less interest to rubyists.
14
14
  #
15
- # In this example, words that appear in one book (Dracula) are colored white
15
+ # In this example, words that appear in one book (Dracula) are colored white
16
16
  # whilst words in the other book (Frankenstein) are colored black.
17
17
  #
18
18
  load_library 'word'
19
19
 
20
- DRACULA = "dracula.txt"
21
- FRANKENSTEIN = "frankenstein.txt"
20
+ DRACULA = 'dracula.txt'
21
+ FRANKENSTEIN = 'frankenstein.txt'
22
+ DRAC = /#{DRACULA}/
23
+ FRANK = /#{FRANKENSTEIN}/
22
24
 
23
25
  attr_accessor :words
24
26
 
@@ -31,7 +33,7 @@ def setup
31
33
  load_file(DRACULA)
32
34
  load_file(FRANKENSTEIN)
33
35
  # Create the font
34
- text_font(create_font("Georgia", 24))
36
+ text_font(create_font('Georgia', 24))
35
37
  end
36
38
 
37
39
  def draw
@@ -47,29 +49,29 @@ end
47
49
 
48
50
  # Load a file
49
51
  def load_file(filename)
50
- tokens = File.open(data_path(filename), "r"){|file| file.read.scan(/[\w'-]+/)}
52
+ tokens = File.open(data_path(filename), 'r'){ |file| file.read.scan(/[\w'-]+/)}
51
53
  tokens.each do |s|
52
54
  s = s.downcase
53
55
  # Is the word in the HashMap
54
- if (words.has_key?(s))
56
+ if (words.key?(s))
55
57
  # Get the word object and increase the count
56
58
  # We access objects from a Hash via its key, the String
57
59
  w = words[s]
58
60
  # Which book am I loading?
59
- if (filename == DRACULA)
61
+ if DRAC =~ filename
60
62
  w.increment_dracula
61
- elsif (filename == FRANKENSTEIN)
63
+ elsif FRANK =~ filename
62
64
  w.increment_franken
63
65
  end
64
66
  else
65
67
  # Otherwise make a new word
66
68
  w = Word.new(s)
67
- # And add entry to the Hash
69
+ # And add entry to the Hash
68
70
  # The key for us is the String and the value is the Word object
69
71
  words[s] = w
70
- if (filename == DRACULA)
72
+ if DRAC =~ filename
71
73
  w.increment_dracula
72
- elsif (filename == FRANKENSTEIN)
74
+ elsif FRANK =~ filename
73
75
  w.increment_franken
74
76
  end
75
77
  end
@@ -2,7 +2,7 @@
2
2
  # Loading XML Data
3
3
  # by Daniel Shiffman.
4
4
  #
5
- # This example demonstrates how to use loadXML()
5
+ # This example demonstrates how to use loadXML
6
6
  # to retrieve data from an XML document via a URL
7
7
  #
8
8
 
@@ -11,7 +11,8 @@ attr_reader :zip, :weather, :temperature
11
11
  def setup
12
12
  size(600, 360)
13
13
  @zip = 10003
14
- font = create_font("Merriweather-Light.ttf", 28)
14
+ font = create_font('Times Roman', 28)
15
+ # font = create_font('Merriweather-Light.ttf', 28)
15
16
  text_font(font)
16
17
 
17
18
  # The URL for the XML document
@@ -21,11 +22,11 @@ def setup
21
22
  xml = loadXML(url)
22
23
 
23
24
  # Grab the element we want
24
- forecast = xml.get_child("channel").get_child("item").get_child("yweather:forecast")
25
+ forecast = xml.get_child('channel').get_child('item').get_child('yweather:forecast')
25
26
 
26
27
  # Get the attributes we want
27
- @temperature = forecast.get_int("high")
28
- @weather = forecast.get_string("text")
28
+ @temperature = forecast.get_int('high')
29
+ @weather = forecast.get_string('text')
29
30
  end
30
31
 
31
32
  def draw
@@ -16,22 +16,22 @@ def setup
16
16
  size(640, 360)
17
17
  background(255, 204, 0)
18
18
  frame_rate(24)
19
- @animation1 = Animation.new("PT_Shifty_", 38)
20
- @animation2 = Animation.new("PT_Teddy_", 60)
19
+ @animation1 = Animation.new('PT_Shifty_', 38)
20
+ @animation2 = Animation.new('PT_Teddy_', 60)
21
21
  @ypos = height * 0.25
22
22
  @xpos = 0
23
23
  end
24
24
 
25
25
  def draw
26
26
  dx = mouse_x - xpos
27
- @xpos = xpos + dx/DRAG
27
+ @xpos = xpos + dx / DRAG
28
28
  # Display the sprite at the position xpos, ypos
29
- if (mouse_pressed?)
29
+ if mouse_pressed?
30
30
  background(153, 153, 0)
31
- animation1.display(xpos-animation1.get_width/2, ypos)
31
+ animation1.display(xpos - animation1.get_width / 2, ypos)
32
32
  else
33
33
  background(255, 204, 0)
34
- animation2.display(xpos-animation2.get_width/2, ypos)
34
+ animation2.display(xpos - animation2.get_width / 2, ypos)
35
35
  end
36
36
  end
37
37
 
@@ -41,7 +41,9 @@ class Animation
41
41
  def initialize(image_prefix, count)
42
42
  @image_count = count
43
43
  @frame = 0
44
- @images = (0 ... image_count).map{|i| load_image("%s%04d%s" % [image_prefix, i, ".gif"])}
44
+ @images = (0 ... image_count).map {
45
+ |i| load_image(format('%s%04d%s', image_prefix, i, '.gif'))
46
+ }
45
47
  end
46
48
 
47
49
  def display(xpos, ypos)
@@ -8,34 +8,34 @@
8
8
 
9
9
  NUM_FRAMES = 12 # The number of frames in the animation
10
10
  attr_reader :frame, :images
11
-
11
+
12
12
  def setup
13
13
  size(640, 360)
14
14
  frame_rate(24)
15
15
  @frame = 0
16
16
  @images = []
17
- images << loadImage("PT_anim0000.gif")
18
- images << loadImage("PT_anim0001.gif")
19
- images << loadImage("PT_anim0002.gif")
20
- images << loadImage("PT_anim0003.gif")
21
- images << loadImage("PT_anim0004.gif")
22
- images << loadImage("PT_anim0005.gif")
23
- images << loadImage("PT_anim0006.gif")
24
- images << loadImage("PT_anim0007.gif")
25
- images << loadImage("PT_anim0008.gif")
26
- images << loadImage("PT_anim0009.gif")
27
- images << loadImage("PT_anim0010.gif")
28
- images << loadImage("PT_anim0011.gif")
29
- end
30
-
31
- def draw
17
+ images << load_image('PT_anim0000.gif')
18
+ images << load_image('PT_anim0001.gif')
19
+ images << load_image('PT_anim0002.gif')
20
+ images << load_image('PT_anim0003.gif')
21
+ images << load_image('PT_anim0004.gif')
22
+ images << load_image('PT_anim0005.gif')
23
+ images << load_image('PT_anim0006.gif')
24
+ images << load_image('PT_anim0007.gif')
25
+ images << load_image('PT_anim0008.gif')
26
+ images << load_image('PT_anim0009.gif')
27
+ images << load_image('PT_anim0010.gif')
28
+ images << load_image('PT_anim0011.gif')
29
+ end
30
+
31
+ def draw
32
32
  background(0)
33
33
  @frame = (frame + 1) % NUM_FRAMES # Use % to cycle through frames
34
34
  offset = 0
35
- (-100 ... width).step(images[0].width) do |i|
36
- image(images[(frame+offset) % NUM_FRAMES], i, -20)
35
+ (-100 ... width).step(images[0].width) do |i|
36
+ image(images[(frame + offset) % NUM_FRAMES], i, -20)
37
37
  offset += 2
38
- image(images[(frame+offset) % NUM_FRAMES], i, height/2)
38
+ image(images[(frame + offset) % NUM_FRAMES], i, height / 2)
39
39
  offset += 2
40
40
  end
41
41
  end
@@ -29,7 +29,7 @@ class CA
29
29
  # Reset to generation 0
30
30
  def restart
31
31
  @cells = Array.new(width / SCL, 0)
32
- cells[cells.length/2] = 1 # We arbitrarily start with just the middle cell having a state of "1"
32
+ cells[cells.length/2] = 1 # We arbitrarily start with just the middle cell having a state of '1'
33
33
  @generation = 0
34
34
  end
35
35
 
@@ -8,7 +8,7 @@
8
8
  # When the system reaches bottom of the window, it restarts with a new ruleset
9
9
  # Mouse click restarts as well.
10
10
  #
11
- load_library 'ca'
11
+ load_library :ca
12
12
 
13
13
  attr_reader :ca # An instance object to describe the Wolfram basic Cellular Automata
14
14
 
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # BeginEnd_contour
3
3
  #
4
- # How to cut a shape out of another using begin_contour() and end_contour()
4
+ # How to cut a shape out of another using begin_contour and end_contour
5
5
  #
6
6
 
7
7
  attr_reader :s
@@ -8,9 +8,9 @@ class Wiggler
8
8
  @x = width/2
9
9
  @y = height/2
10
10
  @yoff = 0
11
- # The "original" locations of the vertices make up a circle
11
+ # The 'original' locations of the vertices make up a circle
12
12
  @original = []
13
- (0 ... TWO_PI).step(0.2) do |a|
13
+ (0 ... TAU).step(0.2) do |a|
14
14
  v = PVector.from_angle(a)
15
15
  v.mult(100)
16
16
  original << v
@@ -32,9 +32,9 @@ class Wiggler
32
32
  @xoff = 0
33
33
  # Apply an offset to each vertex
34
34
  (0 ... s.get_vertex_count).each do |i|
35
- # Calculate a new vertex location based on noise around "original" location
35
+ # Calculate a new vertex location based on noise around 'original' location
36
36
  pos = original[i]
37
- a = TWO_PI*noise(xoff,yoff)
37
+ a = TAU*noise(xoff,yoff)
38
38
  r = PVector.from_angle(a)
39
39
  r.mult(4)
40
40
  r.add(pos)
@@ -12,7 +12,7 @@ attr_reader :ps
12
12
  def setup
13
13
  size(640, 360, P2D)
14
14
  # Load the image
15
- sprite = loadImage("sprite.png")
15
+ sprite = loadImage('sprite.png')
16
16
  # A new particle system with 10,000 particles
17
17
  @ps = ParticleSystem.new(width, height, sprite, 10000)
18
18
  # Writing to the depth buffer is disabled to avoid rendering
@@ -32,7 +32,7 @@ def draw
32
32
  # Display frame rate
33
33
  fill(255, 0, 255)
34
34
  text_size(16)
35
- text("Frame rate: #{format('%.2f', frame_rate)}", 10, 20)
35
+ text('Frame rate: #{format('%.2f', frame_rate)}', 10, 20)
36
36
 
37
37
  end
38
38
 
@@ -20,7 +20,7 @@ def setup
20
20
 
21
21
  x = 0
22
22
  # Calculate the path as a sine wave
23
- (0 .. TWO_PI).step(0.1) do |theta|
23
+ (0 .. TAU).step(0.1) do |theta|
24
24
  path.vertex(x,sin(theta)*100)
25
25
  x += 5
26
26
  end