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
@@ -20,3 +20,8 @@
20
20
  y: 179
21
21
  diameter: 44.7
22
22
  label: Melancholy
23
+ - !ruby/struct:BubbleStruct
24
+ x: 516
25
+ y: 217
26
+ diameter: 50
27
+ label: new label
@@ -2,9 +2,9 @@
2
2
 
3
3
  class Bubble
4
4
  include Processing::Proxy
5
-
5
+
6
6
  attr_reader :x, :y, :diameter, :name, :over
7
-
7
+
8
8
  # Create the Bubble
9
9
  def initialize(x, y, diameter, name)
10
10
  @x = x
@@ -13,32 +13,32 @@ class Bubble
13
13
  @name = name
14
14
  @over = false
15
15
  end
16
-
16
+
17
17
  # Checking if mouse is over the Bubble
18
18
  def rollover(px, py)
19
19
  d = dist(px,py,x,y)
20
20
  @over = (d < diameter/2)? true : false
21
21
  end
22
-
22
+
23
23
  # Display the Bubble
24
24
  def display
25
25
  stroke(0)
26
26
  stroke_weight(2)
27
27
  noFill
28
- ellipse(x,y,diameter,diameter)
28
+ ellipse(x, y, diameter, diameter)
29
29
  if (over)
30
30
  fill(0)
31
31
  text_align(CENTER)
32
- text(name, x, y + diameter/2 + 20)
32
+ text(name, x, y + diameter / 2 + 20)
33
33
  end
34
34
  end
35
35
 
36
36
  def to_hash
37
- {"position" => {"x" => x, "y" => y}, "diameter" => diameter, "label" => name}
37
+ {'position' => {'x' => x, 'y' => y}, 'diameter' => diameter, 'label' => name}
38
38
  end
39
39
 
40
40
  def to_struct
41
- BubbleStruct.new(x, y, diameter, name)
41
+ BubbleStruct.new(x, y, diameter, name)
42
42
  end
43
43
  end
44
44
 
@@ -1,29 +1,29 @@
1
1
  #
2
2
  # Loading XML Data
3
- # by Daniel Shiffman.
4
- #
3
+ # by Daniel Shiffman.
4
+ #
5
5
  # This example demonstrates how to use loadXML
6
- # to retrieve data from an XML file and make objects
6
+ # to retrieve data from an XML file and make objects
7
7
  # from that data.
8
8
  #
9
9
  # Here is what the XML looks like:
10
10
  #
11
- # <?xml version="1.0"?>
11
+ # <?xml version='1.0'?>
12
12
  # <bubbles>
13
13
  # <bubble>
14
- # <position x="160" y="103"/>
14
+ # <position x='160' y='103'/>
15
15
  # <diameter>43.19838</diameter>
16
16
  # <label>Happy</label>
17
17
  # </bubble>
18
18
  # <bubble>
19
- # <position x="372" y="137"/>
19
+ # <position x='372' y='137'/>
20
20
  # <diameter>52.42526</diameter>
21
21
  # <label>Sad</label>
22
22
  # </bubble>
23
23
  # </bubbles>
24
24
  #
25
- load_library "bubble"
26
-
25
+ load_library 'bubble'
26
+
27
27
  attr_reader :bubbles, :xml
28
28
 
29
29
  def setup
@@ -41,74 +41,73 @@ def draw
41
41
 
42
42
  text_align(LEFT)
43
43
  fill(0)
44
- text("Click to add bubbles.", 10, height - 10)
44
+ text('Click to add bubbles.', 10, height - 10)
45
45
  end
46
46
 
47
47
  def load_data
48
48
  # Load XML file
49
- @xml = loadXML("data.xml")
50
- # Get all the child nodes named "bubble"
51
- children = xml.get_children("bubble")
49
+ @xml = loadXML('data.xml')
50
+ # Get all the child nodes named 'bubble'
51
+ children = xml.get_children('bubble')
52
52
 
53
- # The size of the array of Bubble objects is determined by the total XML elements named "bubble"
53
+ # The size of the array of Bubble objects is determined by the total XML elements named 'bubble'
54
54
  @bubbles = []
55
55
 
56
- children.each do |element|
56
+ children.each do |element|
57
57
  # The position element has two attributes: x and y
58
- position_element = element.get_child("position")
58
+ position_element = element.get_child('position')
59
59
  # Note how with attributes we can get an integer or directly
60
- x, y = position_element.get_int("x"), position_element.get_int("y")
61
-
62
- # The diameter is the content of the child named "diamater"
63
- diameter_element = element.get_child("diameter")
60
+ x, y = position_element.get_int('x'), position_element.get_int('y')
61
+
62
+ # The diameter is the content of the child named 'diamater'
63
+ diameter_element = element.get_child('diameter')
64
64
  # Note how with the content of an XML node, we retrieve as a String and then convert
65
65
  diameter = (diameter_element.get_content).to_f
66
66
 
67
- # The label is the content of the child named "label"
68
- label_element = element.get_child("label")
67
+ # The label is the content of the child named 'label'
68
+ label_element = element.get_child('label')
69
69
  label = label_element.get_content
70
70
 
71
71
  # Make a Bubble object out of the data read
72
72
  bubbles << Bubble.new(x, y, diameter, label)
73
- end
73
+ end
74
74
 
75
75
  end
76
76
 
77
77
  # Still need to work on adding and deleting
78
78
 
79
79
  def mouse_pressed
80
-
80
+
81
81
  # Create a new XML bubble element
82
- bubble = xml.add_child("bubble")
83
-
82
+ bubble = xml.add_child('bubble')
83
+
84
84
  # Set the poisition element
85
- position = bubble.add_child("position")
85
+ position = bubble.add_child('position')
86
86
  # Here we can set attributes as integers directly
87
- position.set_int("x",mouseX)
88
- position.set_int("y",mouseY)
89
-
87
+ position.set_int('x', mouseX)
88
+ position.set_int('y', mouseY)
89
+
90
90
  # Set the diameter element
91
- diameter = bubble.add_child("diameter")
91
+ diameter = bubble.add_child('diameter')
92
92
  # Here for a node's content, we have to convert to a String
93
93
  diameter.set_content(rand(40.0 .. 80).to_s)
94
-
94
+
95
95
  # Set a label
96
- label = bubble.add_child("label")
97
- label.set_content("New label")
98
-
99
-
96
+ label = bubble.add_child('label')
97
+ label.set_content('New label')
98
+
99
+
100
100
  # Here we are removing the oldest bubble if there are more than 10
101
- children = xml.get_children("bubble")
101
+ children = xml.get_children('bubble')
102
102
  # If the XML file has more than 10 bubble elements
103
103
  if (children.length > 10)
104
104
  # Delete the first one
105
105
  xml.remove_child(children[0])
106
106
  end
107
-
107
+
108
108
  # Save a new XML file
109
- saveXML(xml,"data/data.xml")
110
-
111
- # reload the new data
112
- load_data
113
- end
109
+ saveXML(xml, 'data/data.xml')
114
110
 
111
+ # reload the new data
112
+ load_data
113
+ end
@@ -1,20 +1,20 @@
1
- # This example demonstrates how easily "sketch data" can be retrieved from a json file
1
+ # This example demonstrates how easily 'sketch data' can be retrieved from a json file
2
2
  # in ruby-processing. Note this sketch re-uses the Bubble class from the bubble library.
3
3
  # The BubbleData class, can load, store and create instances of Bubble (and request them
4
4
  # to display and/or show their label, when 'mouse over').
5
5
  # @author Martin Prout, after Daniel Shiffmans version for processing
6
6
  #
7
- require "json"
7
+ require 'json'
8
8
 
9
9
  load_library :bubble
10
10
 
11
11
  attr_reader :bubble_data
12
12
 
13
- def setup()
13
+ def setup
14
14
  size(640, 360)
15
15
  # initialize bubble_data with 'key' and read data from 'file path'
16
- @bubble_data = BubbleData.new "bubbles"
17
- bubble_data.load_data "data/data.json"
16
+ @bubble_data = BubbleData.new 'bubbles'
17
+ bubble_data.load_data 'data/data.json'
18
18
  end
19
19
 
20
20
  def draw
@@ -47,7 +47,7 @@ class BubbleData
47
47
  end
48
48
 
49
49
  def create_new_bubble x, y
50
- self.add Bubble.new(x, y, rand(40 .. 80), "new label")
50
+ self.add Bubble.new(x, y, rand(40 .. 80), 'new label')
51
51
  save_data
52
52
  load_data path
53
53
  end
@@ -63,16 +63,16 @@ class BubbleData
63
63
 
64
64
  def load_data path
65
65
  @path = path
66
- source_string = open(path, "r"){ |file| file.read }
66
+ source_string = open(path, 'r'){ |file| file.read }
67
67
  data = JSON.parse(source_string)[key]
68
68
  bubbles.clear
69
69
  # iterate the bubble_data array, and create an array of bubbles
70
70
  data.each do |point|
71
71
  self.add Bubble.new(
72
- point["position"]["x"],
73
- point["position"]["y"],
74
- point["diameter"],
75
- point["label"])
72
+ point['position']['x'],
73
+ point['position']['y'],
74
+ point['diameter'],
75
+ point['label'])
76
76
  end
77
77
  end
78
78
 
@@ -1,7 +1,7 @@
1
1
  ######################################
2
2
  # Yet another examples of reading and
3
3
  # writing to some form of markup,
4
- # appropriately yaml using ruby structs
4
+ # appropriately yaml using ruby structs
5
5
  # by Martin Prout after Dan Shiffman
6
6
  ####################################
7
7
  load_library :bubble
@@ -9,10 +9,10 @@ load_library :bubble
9
9
  attr_reader :bubble_data
10
10
 
11
11
 
12
- def setup()
12
+ def setup
13
13
  size(640, 360)
14
14
  @bubble_data = BubbleData.new :bubbles
15
- bubble_data.load_data "data/struct_data.yml"
15
+ bubble_data.load_data 'data/struct_data.yml'
16
16
  end
17
17
 
18
18
  def draw
@@ -26,10 +26,13 @@ def mouse_pressed
26
26
  bubble_data.create_new_bubble(mouse_x, mouse_y)
27
27
  end
28
28
 
29
+ require 'forwardable'
29
30
 
30
31
  class BubbleData
31
32
  include Enumerable
32
-
33
+ extend Forwardable
34
+ def_delegators(:@bubble_array, :clear, :each, :<<, :shift, :size)
35
+
33
36
  MAX_BUBBLE = 10
34
37
 
35
38
  attr_reader :path, :bubble_array
@@ -37,29 +40,25 @@ class BubbleData
37
40
  @bubble_array = []
38
41
  @key = key
39
42
  end
40
-
41
- def each &block
42
- bubble_array.each &block
43
- end
44
-
43
+
45
44
  def create_new_bubble x, y
46
- self.add Bubble.new(x, y, rand(40 .. 80), "new label")
47
- save_data
45
+ self.add Bubble.new(x, y, rand(40 .. 80), 'new label')
46
+ save_data
48
47
  load_data path
49
48
  end
50
49
 
51
50
  def add bubble
52
- bubble_array << bubble
53
- bubble_array.shift if bubble_array.size > MAX_BUBBLE
54
- end
55
-
51
+ self << bubble
52
+ self.shift if self.size > MAX_BUBBLE
53
+ end
54
+
56
55
  def load_data path
57
56
  @path = path
58
57
  yaml = Psych.load_file(path)
59
58
  # we are storing the data as an array of RubyStruct, in a hash with
60
59
  # a symbol as the key (the latter only to show we can, it makes no sense)
61
- data = yaml[@key]
62
- bubble_array.clear
60
+ data = yaml[@key]
61
+ self.clear
63
62
  # iterate the bubble_data array, and populate the array of bubbles
64
63
  data.each do |pt|
65
64
  self.add Bubble.new(pt.x, pt.y, pt.diameter, pt.label)
@@ -71,15 +70,15 @@ class BubbleData
71
70
  bubble.display
72
71
  bubble.rollover(x, y)
73
72
  end
74
- end
73
+ end
74
+
75
+ private
75
76
 
76
- private
77
-
78
77
  def save_data
79
- hash = { @key => self.map{ |point| point.to_struct } }
78
+ hash = { @key => self.map { |point| point.to_struct } }
80
79
  yaml = hash.to_yaml
81
- # overwite existing 'struct_data.yaml'
82
- open(path, 'w:UTF-8') {|f| f.write(yaml) }
80
+ # overwite existing 'struct_data.yaml'
81
+ open(path, 'w:UTF-8') { |f| f.write(yaml) }
83
82
  end
84
83
 
85
84
  end
@@ -16,7 +16,7 @@
16
16
  #
17
17
  require 'csv'
18
18
 
19
- load_library "bubble"
19
+ load_library 'bubble'
20
20
 
21
21
  attr_reader :bubbles, :data
22
22
 
@@ -35,23 +35,23 @@ def draw
35
35
 
36
36
  text_align(LEFT)
37
37
  fill(0)
38
- text("Click to add bubbles.", 10, height - 10)
38
+ text('Click to add bubbles.', 10, height - 10)
39
39
  end
40
40
 
41
41
  def load_data
42
42
  # Load CSV file into an Array of Hash objects
43
43
  # :headers option indicates the file has a header row
44
- @data = CSV.read("data/data.csv", :headers => true).map{|row| row.to_hash}
44
+ @data = CSV.read('data/data.csv', :headers => true).map{|row| row.to_hash}
45
45
 
46
- # The size of the array of Bubble objects is determined by the total number of "rows" in the CSV
46
+ # The size of the array of Bubble objects is determined by the total number of 'rows' in the CSV
47
47
  @bubbles = []
48
48
 
49
49
  data.each do |row|
50
50
  # You access the values via their column name (set by using headers option above)
51
- x = row["x"].to_f
52
- y = row["y"].to_f
53
- d = row["diameter"].to_f
54
- n = row["name"]
51
+ x = row['x'].to_f
52
+ y = row['y'].to_f
53
+ d = row['diameter'].to_f
54
+ n = row['name']
55
55
  # Make a Bubble object out of the data read
56
56
  bubbles << Bubble.new(x, y, d, n)
57
57
  end
@@ -59,8 +59,8 @@ def load_data
59
59
  end
60
60
 
61
61
  def mouse_pressed
62
- # Create a new "row" hash
63
- row = {"x" => mouse_x.to_s, "y" => mouse_y.to_s, "diameter" => random(40, 80).to_s, "name" => "Blah"}
62
+ # Create a new 'row' hash
63
+ row = {'x' => mouse_x.to_s, 'y' => mouse_y.to_s, 'diameter' => random(40, 80).to_s, 'name' => 'Blah'}
64
64
  # add the row to the existing data array
65
65
  data << row
66
66
 
@@ -69,7 +69,7 @@ def mouse_pressed
69
69
  # Delete the oldest row
70
70
  data.shift
71
71
  end
72
- # read column names from data, and generate csv "string" that can be written to file
72
+ # read column names from data, and generate csv 'string' that can be written to file
73
73
  column_names = data.first.keys
74
74
  s = CSV.generate do |csv|
75
75
  csv << column_names
@@ -78,7 +78,7 @@ def mouse_pressed
78
78
  end
79
79
  end
80
80
  # Writing the csv data back to the same file, (also specify UTF-8 format)
81
- File.open("data/data.csv", 'w:UTF-8') { |file| file.write(s)}
81
+ File.open('data/data.csv', 'w:UTF-8') { |file| file.write(s)}
82
82
  # And reloading it
83
83
  load_data
84
84
  end
@@ -11,8 +11,8 @@ attr_reader :bubble_data
11
11
  def setup()
12
12
  size(640, 360)
13
13
  # load data from file
14
- @bubble_data = BubbleData.new "bubbles"
15
- bubble_data.load_data "data/data.yml"
14
+ @bubble_data = BubbleData.new 'bubbles'
15
+ bubble_data.load_data 'data/data.yml'
16
16
  end
17
17
 
18
18
  def draw
@@ -41,7 +41,7 @@ class BubbleData
41
41
  end
42
42
 
43
43
  def create_new_bubble x, y
44
- self.add Bubble.new(x, y, rand(40 .. 80), "new label")
44
+ self.add Bubble.new(x, y, rand(40 .. 80), 'new label')
45
45
  save_data
46
46
  load_data path
47
47
  end
@@ -57,16 +57,16 @@ class BubbleData
57
57
 
58
58
  def load_data path
59
59
  @path = path
60
- yaml = Psych.load_file("data/data.yml")
60
+ yaml = Psych.load_file('data/data.yml')
61
61
  data = yaml[key]
62
62
  bubbles.clear
63
63
  # iterate the bubble_data array, and create an array of bubbles
64
64
  data.each do |point|
65
65
  self.add Bubble.new(
66
- point["position"]["x"],
67
- point["position"]["y"],
68
- point["diameter"],
69
- point["label"])
66
+ point['position']['x'],
67
+ point['position']['y'],
68
+ point['diameter'],
69
+ point['label'])
70
70
  end
71
71
  end
72
72
 
@@ -82,8 +82,6 @@ class BubbleData
82
82
  hash = { key => self.map{ |point| point.to_hash } }
83
83
  yaml = hash.to_yaml
84
84
  # overwite existing 'data.yaml'
85
- open("data/data.yml", 'w:UTF-8') {|f| f.write(yaml) }
86
- end
87
-
85
+ open('data/data.yml', 'w:UTF-8') { |f| f.write(yaml) }
86
+ end
88
87
  end
89
-