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.
- checksums.yaml +4 -4
- data/lib/rpextras.jar +0 -0
- data/lib/ruby-processing.rb +8 -6
- data/lib/ruby-processing/app.rb +54 -67
- data/lib/ruby-processing/config.rb +7 -7
- data/lib/ruby-processing/exporters/application_exporter.rb +37 -38
- data/lib/ruby-processing/exporters/base_exporter.rb +34 -37
- data/lib/ruby-processing/exporters/creator.rb +27 -25
- data/lib/ruby-processing/helper_methods.rb +18 -22
- data/lib/ruby-processing/helpers/numeric.rb +5 -6
- data/lib/ruby-processing/helpers/string.rb +11 -20
- data/lib/ruby-processing/library_loader.rb +33 -35
- data/lib/ruby-processing/runner.rb +118 -65
- data/lib/ruby-processing/runners/base.rb +21 -26
- data/lib/ruby-processing/runners/live.rb +3 -4
- data/lib/ruby-processing/runners/run.rb +1 -3
- data/lib/ruby-processing/runners/watch.rb +8 -8
- data/lib/ruby-processing/version.rb +1 -1
- data/lib/templates/application/lib/args.txt.erb +1 -1
- data/lib/templates/application/run.erb +3 -3
- data/library/control_panel/control_panel.rb +29 -29
- data/library/fastmath/fastmath.rb +3 -0
- data/library/file_chooser/file_chooser.rb +11 -13
- data/library/vecmath/vecmath.rb +6 -35
- data/samples/Rakefile +3 -1
- data/samples/configRP5/configRP5.pde +150 -0
- data/samples/contributed/Rakefile +6 -6
- data/samples/contributed/animator.rb +6 -6
- data/samples/contributed/bezier_playground.rb +29 -68
- data/samples/contributed/circle_collision.rb +6 -13
- data/samples/contributed/elegant_ball.rb +14 -17
- data/samples/contributed/empathy.rb +8 -5
- data/samples/contributed/fibonacci_sphere.rb +10 -49
- data/samples/contributed/full_screen.rb +1 -1
- data/samples/contributed/grapher.rb +10 -9
- data/samples/contributed/gravity.rb +11 -16
- data/samples/contributed/jwishy.rb +18 -20
- data/samples/contributed/quadraticvertex.rb +26 -26
- data/samples/external_library/java_processing/custom/landscape.rb +6 -4
- data/samples/external_library/java_processing/hemesh/twin_iso.rb +69 -71
- data/samples/external_library/java_processing/pbox2d/bumpy_surface_noise.rb +57 -0
- data/samples/external_library/java_processing/pbox2d/contact_test.rb +23 -0
- data/samples/external_library/java_processing/pbox2d/data/java_args.txt +2 -0
- data/samples/external_library/java_processing/pbox2d/library/custom_shape/custom_shape.rb +158 -0
- data/samples/external_library/java_processing/pbox2d/library/particle_system/particle_system.rb +212 -0
- data/samples/external_library/java_processing/pbox2d/library/surface/surface.rb +154 -0
- data/samples/external_library/java_processing/pbox2d/liquidy.rb +58 -0
- data/samples/external_library/java_processing/pbox2d/polygons.rb +58 -0
- data/samples/external_library/java_processing/toxiclibs/library/vbo/vbo.rb +52 -0
- data/samples/external_library/java_processing/toxiclibs/model_align.rb +9 -16
- data/samples/processing_app/basics/color/color_wheel.rb +1 -1
- data/samples/processing_app/basics/form/regular_polygon.rb +2 -2
- data/samples/processing_app/basics/form/rgb_cube.rb +2 -2
- data/samples/processing_app/basics/form/shape_primitives.rb +1 -1
- data/samples/processing_app/basics/form/star.rb +2 -2
- data/samples/processing_app/basics/input/clock.rb +21 -16
- data/samples/processing_app/basics/input/storing_input.rb +6 -6
- data/samples/processing_app/basics/math/additive_wave.rb +1 -1
- data/samples/processing_app/basics/math/sine.rb +2 -2
- data/samples/processing_app/basics/math/sine_cosine.rb +1 -1
- data/samples/processing_app/basics/math/sine_wave.rb +1 -1
- data/samples/processing_app/basics/objects/inheritance.rb +2 -0
- data/samples/processing_app/basics/objects/inheritance_two.rb +88 -0
- data/samples/processing_app/basics/objects/module.rb +89 -0
- data/samples/processing_app/{library/vecmath/drawolver.rb → basics/objects/module_two.rb} +1 -1
- data/samples/processing_app/basics/objects/multiple_constructors.rb +5 -0
- data/samples/processing_app/basics/objects/struct.rb +38 -0
- data/samples/processing_app/basics/structure/recursion2.rb +1 -1
- data/samples/processing_app/basics/transform/birds.rb +7 -10
- data/samples/processing_app/basics/transform/library/bird/bird.rb +3 -3
- data/samples/processing_app/basics/transform/rotate.rb +1 -1
- data/samples/processing_app/basics/transform/rotate1.rb +1 -1
- data/samples/processing_app/basics/transform/rotate_x_y.rb +1 -1
- data/samples/processing_app/demos/graphics/bezier_patch.rb +1 -38
- data/samples/processing_app/demos/graphics/trefoil.rb +50 -40
- data/samples/processing_app/demos/graphics/wiggling.rb +36 -38
- data/samples/processing_app/demos/performance/cubic_grid_retained.rb +14 -14
- data/samples/processing_app/demos/performance/esfera.rb +27 -39
- data/samples/processing_app/demos/performance/text_rendering.rb +1 -1
- data/samples/processing_app/library/fastmath/clock.rb +44 -0
- data/samples/processing_app/library/pdf/complex_3D.rb +26 -24
- data/samples/processing_app/library/vecmath/{Rakefile → arcball/Rakefile} +6 -6
- data/samples/processing_app/library/vecmath/arcball/arcball_box.rb +23 -0
- data/samples/processing_app/library/vecmath/arcball/arcball_radius.rb +23 -0
- data/samples/processing_app/library/vecmath/arcball/arcball_shape.rb +29 -0
- data/samples/processing_app/library/vecmath/{README.txt → vec2d/README.txt} +0 -0
- data/samples/processing_app/library/vecmath/vec2d/Rakefile +30 -0
- data/samples/processing_app/library/vecmath/{acceleration_with_vectors.rb → vec2d/acceleration_with_vectors.rb} +4 -5
- data/samples/processing_app/library/vecmath/{bouncing_ball.rb → vec2d/bouncing_ball.rb} +9 -15
- data/samples/processing_app/library/vecmath/{circle_collision.rb → vec2d/circle_collision.rb} +46 -51
- data/samples/processing_app/library/vecmath/{data → vec2d/data}/java_args.txt +0 -0
- data/samples/processing_app/library/vecmath/{data → vec2d/data}/sprite.png +0 -0
- data/samples/processing_app/library/vecmath/{data → vec2d/data}/texture.png +0 -0
- data/samples/processing_app/library/vecmath/{flocking.rb → vec2d/flocking.rb} +3 -6
- data/samples/processing_app/library/vecmath/{library → vec2d/library}/flock/flock.rb +47 -67
- data/samples/processing_app/library/vecmath/{library → vec2d/library}/particle/particle_system.rb +5 -5
- data/samples/processing_app/library/vecmath/vec2d/library/tile/tile.rb +85 -0
- data/samples/processing_app/library/vecmath/{morph.rb → vec2d/morph.rb} +17 -16
- data/samples/processing_app/library/vecmath/{multiple_particle_systems.rb → vec2d/multiple_particle_systems.rb} +11 -28
- data/samples/processing_app/library/vecmath/{particle_system_pshape.rb → vec2d/particle_system_pshape.rb} +4 -6
- data/samples/processing_app/library/vecmath/vec2d/penrose.rb +71 -0
- data/samples/processing_app/library/vecmath/{reflection1.rb → vec2d/reflection1.rb} +6 -6
- data/samples/processing_app/library/vecmath/{seeking_neural.rb → vec2d/seeking_neural.rb} +12 -16
- data/samples/processing_app/library/vecmath/{simple_particle_system.rb → vec2d/simple_particle_system.rb} +8 -12
- data/samples/processing_app/library/vecmath/{smoke_particle_system.rb → vec2d/smoke_particle_system.rb} +8 -13
- data/samples/processing_app/library/vecmath/{vector_math.rb → vec2d/vector_math.rb} +0 -0
- data/samples/processing_app/library/vecmath/{library/wiggler/wiggler.rb → vec2d/wiggle_pshape.rb} +28 -4
- data/samples/processing_app/library/vecmath/vec3d/Rakefile +30 -0
- data/samples/processing_app/library/vecmath/vec3d/drawolver.rb +86 -0
- data/samples/processing_app/library/vecmath/vec3d/frame_of_reference.rb +103 -0
- data/samples/processing_app/library/vecmath/{hilbert_fractal.rb → vec3d/hilbert_fractal.rb} +5 -33
- data/samples/processing_app/library/vecmath/vec3d/library/geometry/geometry.rb +3 -0
- data/samples/processing_app/library/vecmath/vec3d/library/geometry/lib/cylinder.rb +44 -0
- data/samples/processing_app/library/vecmath/vec3d/library/geometry/lib/mat4.rb +28 -0
- data/samples/processing_app/library/vecmath/vec3d/library/geometry/lib/plane.rb +60 -0
- data/samples/processing_app/library/vecmath/{library → vec3d/library}/hilbert/hilbert.rb +14 -17
- data/samples/processing_app/library/vecmath/{retained_menger.rb → vec3d/retained_menger.rb} +20 -55
- data/samples/processing_app/topics/advanced_data/Rakefile +6 -6
- data/samples/processing_app/topics/advanced_data/counting_words.rb +7 -7
- data/samples/processing_app/topics/advanced_data/data/data.xml +0 -15
- data/samples/processing_app/topics/advanced_data/data/struct_data.yml +5 -0
- data/samples/processing_app/topics/advanced_data/library/bubble/bubble.rb +8 -8
- data/samples/processing_app/topics/advanced_data/load_save_XML.rb +41 -42
- data/samples/processing_app/topics/advanced_data/load_save_json.rb +11 -11
- data/samples/processing_app/topics/advanced_data/load_save_struct_yaml.rb +22 -23
- data/samples/processing_app/topics/advanced_data/load_save_table.rb +12 -12
- data/samples/processing_app/topics/advanced_data/load_save_yaml.rb +10 -12
- data/samples/processing_app/topics/advanced_data/regex.rb +5 -6
- data/samples/processing_app/topics/advanced_data/threads.rb +27 -27
- data/samples/processing_app/topics/advanced_data/threads_two.rb +3 -2
- data/samples/processing_app/topics/advanced_data/word_frequency.rb +18 -16
- data/samples/processing_app/topics/advanced_data/yahoo_weather.rb +6 -5
- data/samples/processing_app/topics/animation/animated_sprite.rb +9 -7
- data/samples/processing_app/topics/animation/sequential.rb +19 -19
- data/samples/processing_app/topics/cellular_automata/library/ca/ca.rb +1 -1
- data/samples/processing_app/topics/cellular_automata/wolfram.rb +1 -1
- data/samples/processing_app/topics/create_shapes/begin_end_contour.rb +1 -1
- data/samples/processing_app/topics/create_shapes/library/wiggler/wiggler.rb +4 -4
- data/samples/processing_app/topics/create_shapes/particle_system_pshape.rb +2 -2
- data/samples/processing_app/topics/create_shapes/path_pshape.rb +1 -1
- data/samples/processing_app/topics/create_shapes/polygon_pshape_oo3.rb +1 -1
- data/samples/processing_app/topics/create_shapes/polygon_shape.rb +3 -3
- data/samples/processing_app/topics/file_io/load_file1.rb +1 -1
- data/samples/processing_app/topics/file_io/save_frames.rb +5 -5
- data/samples/processing_app/topics/file_io/save_one_image.rb +2 -2
- data/samples/processing_app/topics/file_io/tile_images.rb +1 -1
- data/samples/processing_app/topics/gui/scrollbar.rb +3 -3
- data/samples/processing_app/topics/image_processing/blending.rb +13 -13
- data/samples/processing_app/topics/image_processing/blur.rb +1 -1
- data/samples/processing_app/topics/image_processing/brightness.rb +1 -1
- data/samples/processing_app/topics/image_processing/convolution.rb +1 -1
- data/samples/processing_app/topics/image_processing/edge_detection.rb +4 -4
- data/samples/processing_app/topics/image_processing/explode.rb +1 -1
- data/samples/processing_app/topics/image_processing/extrusion.rb +1 -1
- data/samples/processing_app/topics/image_processing/histogram.rb +1 -1
- data/samples/processing_app/topics/image_processing/linear_image.rb +1 -1
- data/samples/processing_app/topics/image_processing/pixel_array.rb +1 -1
- data/samples/processing_app/topics/image_processing/zoom.rb +2 -2
- data/samples/processing_app/topics/lsystems/Rakefile +6 -6
- data/samples/processing_app/topics/lsystems/chequer.rb +4 -10
- data/samples/processing_app/topics/lsystems/csplant.rb +25 -25
- data/samples/processing_app/topics/lsystems/cstest.rb +9 -4
- data/samples/processing_app/topics/lsystems/david_tour.rb +14 -16
- data/samples/processing_app/topics/lsystems/koch.rb +8 -18
- data/samples/processing_app/topics/lsystems/library/cs_grammar/cs_grammar.rb +18 -24
- data/samples/processing_app/topics/lsystems/library/grammar/grammar.rb +7 -9
- data/samples/processing_app/topics/lsystems/library/koch/koch_fractal.rb +75 -94
- data/samples/processing_app/topics/lsystems/library/stochastic_grammar/stochastic_grammar.rb +11 -13
- data/samples/processing_app/topics/lsystems/mpeano.rb +29 -32
- data/samples/processing_app/topics/lsystems/peano.rb +19 -21
- data/samples/processing_app/topics/lsystems/penrose.rb +31 -37
- data/samples/processing_app/topics/lsystems/penrose_snowflake.rb +10 -15
- data/samples/processing_app/topics/lsystems/pentagonal.rb +20 -23
- data/samples/processing_app/topics/lsystems/snake_kolam.rb +13 -13
- data/samples/processing_app/topics/lsystems/stochastic_test.rb +25 -28
- data/samples/processing_app/topics/lsystems/three_d_tree.rb +25 -24
- data/samples/processing_app/topics/motion/bouncy_bubbles.rb +17 -17
- data/samples/processing_app/topics/motion/cubes_in_cube.rb +1 -3
- data/samples/processing_app/topics/motion/library/cube/cube.rb +2 -2
- data/samples/processing_app/topics/motion/reflection2.rb +1 -1
- data/samples/processing_app/topics/shaders/blur_filter.rb +3 -3
- data/samples/processing_app/topics/shaders/bw_shader.rb +3 -3
- data/samples/processing_app/topics/shaders/conway.rb +5 -5
- data/samples/processing_app/topics/shaders/deform.rb +5 -5
- data/samples/processing_app/topics/shaders/edge_detect.rb +3 -5
- data/samples/processing_app/topics/shaders/glossy_fish_eye.rb +15 -21
- data/samples/processing_app/topics/shaders/glsl_heightmap_noise.rb +21 -19
- data/samples/processing_app/topics/shaders/image_mask.rb +6 -6
- data/samples/processing_app/topics/shaders/landscape.rb +4 -4
- data/samples/processing_app/topics/shaders/monjori.rb +15 -15
- data/samples/processing_app/topics/shaders/nebula.rb +3 -3
- data/samples/processing_app/topics/shaders/sep_blur.rb +15 -15
- data/samples/processing_app/topics/shaders/toon_shading.rb +2 -2
- data/samples/processing_app/topics/simulate/chain.rb +16 -14
- data/samples/processing_app/topics/simulate/smoke_particle_system.rb +3 -3
- data/samples/processing_app/topics/vectors/acceleration_with_vectors.rb +3 -2
- data/samples/processing_app/topics/vectors/bouncing_ball.rb +1 -0
- data/samples/processing_app/topics/vectors/vector_math.rb +2 -1
- data/vendors/Rakefile +15 -3
- metadata +99 -86
- data/.gitignore +0 -13
- data/.travis.yml +0 -6
- data/.yardopts +0 -5
- data/CHANGELOG +0 -316
- data/CONTRIBUTING.md +0 -35
- data/Gemfile +0 -6
- data/LICENSE.md +0 -39
- data/README.md +0 -119
- data/Rakefile +0 -37
- data/bin/install_jruby_complete +0 -13
- data/lib/ruby-processing/exporters/exporters.rb +0 -7
- data/library/vecmath/lib/arcball.rb +0 -64
- data/library/vecmath/lib/quaternion.rb +0 -62
- data/library/vecmath/lib/vec.rb +0 -232
- data/ruby-processing.gemspec +0 -54
- data/samples/processing_app/library/pdf/.gitignore +0 -1
- data/samples/processing_app/library/vecmath/retained_test.rb +0 -65
- data/samples/processing_app/library/vecmath/retained_test2.rb +0 -65
- data/samples/processing_app/library/vecmath/wiggle_pshape.rb +0 -22
- data/test/README.md +0 -6
- data/test/basic.rb +0 -14
- data/test/draw_ex.rb +0 -12
- data/test/graphics.rb +0 -7
- data/test/p2d.rb +0 -14
- data/test/p3d.rb +0 -14
- data/test/rp5_test.rb +0 -86
- data/test/setup_ex.rb +0 -12
|
@@ -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
|
-
{
|
|
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=
|
|
11
|
+
# <?xml version='1.0'?>
|
|
12
12
|
# <bubbles>
|
|
13
13
|
# <bubble>
|
|
14
|
-
# <position x=
|
|
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=
|
|
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
|
|
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(
|
|
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(
|
|
50
|
-
# Get all the child nodes named
|
|
51
|
-
children = xml.get_children(
|
|
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
|
|
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(
|
|
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(
|
|
61
|
-
|
|
62
|
-
# The diameter is the content of the child named
|
|
63
|
-
diameter_element = element.get_child(
|
|
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
|
|
68
|
-
label_element = element.get_child(
|
|
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(
|
|
83
|
-
|
|
82
|
+
bubble = xml.add_child('bubble')
|
|
83
|
+
|
|
84
84
|
# Set the poisition element
|
|
85
|
-
position = bubble.add_child(
|
|
85
|
+
position = bubble.add_child('position')
|
|
86
86
|
# Here we can set attributes as integers directly
|
|
87
|
-
position.set_int(
|
|
88
|
-
position.set_int(
|
|
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(
|
|
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(
|
|
97
|
-
label.set_content(
|
|
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(
|
|
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,
|
|
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
|
|
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
|
|
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
|
|
17
|
-
bubble_data.load_data
|
|
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),
|
|
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,
|
|
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[
|
|
73
|
-
point[
|
|
74
|
-
point[
|
|
75
|
-
point[
|
|
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
|
|
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),
|
|
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
|
-
|
|
53
|
-
|
|
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
|
-
|
|
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
|
|
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(
|
|
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(
|
|
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
|
|
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[
|
|
52
|
-
y = row[
|
|
53
|
-
d = row[
|
|
54
|
-
n = row[
|
|
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
|
|
63
|
-
row = {
|
|
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
|
|
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(
|
|
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
|
|
15
|
-
bubble_data.load_data
|
|
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),
|
|
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(
|
|
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[
|
|
67
|
-
point[
|
|
68
|
-
point[
|
|
69
|
-
point[
|
|
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(
|
|
86
|
-
end
|
|
87
|
-
|
|
85
|
+
open('data/data.yml', 'w:UTF-8') { |f| f.write(yaml) }
|
|
86
|
+
end
|
|
88
87
|
end
|
|
89
|
-
|