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
|
@@ -18,17 +18,11 @@ class Ball
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
def check_boundary width, height
|
|
21
|
-
if (
|
|
22
|
-
position.x = width - r
|
|
21
|
+
if !(r .. width - r).include?(position.x)
|
|
22
|
+
(position.x > width - r)? position.x = width - r : position.x = r
|
|
23
23
|
velocity.x *= -1
|
|
24
|
-
elsif (
|
|
25
|
-
position.
|
|
26
|
-
velocity.x *= -1
|
|
27
|
-
elsif (position.y > height - r)
|
|
28
|
-
position.y = height - r
|
|
29
|
-
velocity.y *= -1
|
|
30
|
-
elsif (position.y < r)
|
|
31
|
-
position.y = r
|
|
24
|
+
elsif !(r .. height - r).include?(position.y)
|
|
25
|
+
(position.y > height - r)? position.y = height - r : position.y = r
|
|
32
26
|
velocity.y *= -1
|
|
33
27
|
end
|
|
34
28
|
end
|
|
@@ -39,10 +33,9 @@ class Ball
|
|
|
39
33
|
difference = other_ball.position - position
|
|
40
34
|
|
|
41
35
|
# calculate magnitude of the vector separating the balls
|
|
36
|
+
|
|
42
37
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if dist_mag_squared < (r + other_ball.r) * (r + other_ball.r)
|
|
38
|
+
if difference.mag < (r + other_ball.r)
|
|
46
39
|
# get angle of difference
|
|
47
40
|
theta = difference.heading
|
|
48
41
|
# precalculate trig values
|
|
@@ -5,8 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
load_library :vecmath
|
|
7
7
|
|
|
8
|
+
attr_reader :renderer
|
|
9
|
+
|
|
8
10
|
def setup
|
|
9
11
|
size(800, 800, P3D)
|
|
12
|
+
@renderer = AppRender.new(self)
|
|
10
13
|
color_mode(RGB, 1)
|
|
11
14
|
end
|
|
12
15
|
|
|
@@ -79,20 +82,18 @@ def draw_icosahedron(depth, r, spherical)
|
|
|
79
82
|
gr = (1.0 + Math.sqrt(5.0)) / 2.0
|
|
80
83
|
h = r / Math.sqrt(1.0 + gr * gr)
|
|
81
84
|
v =
|
|
82
|
-
|
|
83
|
-
Vec3D.new(0, -h, h*
|
|
84
|
-
Vec3D.new(h, -h*
|
|
85
|
-
Vec3D.new(-h*
|
|
85
|
+
[
|
|
86
|
+
Vec3D.new(0, -h, h * r), Vec3D.new(0, -h, -h * r), Vec3D.new(0, h, -h * r), Vec3D.new(0, h, h * r),
|
|
87
|
+
Vec3D.new(h, -h * r, 0), Vec3D.new(h, h * r, 0), Vec3D.new(-h, h * r, 0), Vec3D.new(-h, -h * r, 0),
|
|
88
|
+
Vec3D.new(-h * r, 0, h), Vec3D.new(-h * r, 0, -h), Vec3D.new(h * r, 0, -h), Vec3D.new(h * r, 0, h)
|
|
86
89
|
]
|
|
87
90
|
|
|
88
91
|
# Draw the 20 triangular faces of the icosahedron.
|
|
89
|
-
unless spherical
|
|
90
|
-
r = 0.0
|
|
91
|
-
end
|
|
92
|
+
r = 0.0 unless spherical
|
|
92
93
|
|
|
93
94
|
begin_shape(TRIANGLES)
|
|
94
95
|
|
|
95
|
-
draw_triangle(depth, r, v[0], v[7],v[4])
|
|
96
|
+
draw_triangle(depth, r, v[0], v[7], v[4])
|
|
96
97
|
draw_triangle(depth, r, v[0], v[4], v[11])
|
|
97
98
|
draw_triangle(depth, r, v[0], v[11], v[3])
|
|
98
99
|
draw_triangle(depth, r, v[0], v[3], v[8])
|
|
@@ -124,16 +125,16 @@ end
|
|
|
124
125
|
#
|
|
125
126
|
def draw_triangle(depth, r, p1, p2, p3)
|
|
126
127
|
|
|
127
|
-
if (depth == 1)
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
128
|
+
if (depth == 1)
|
|
129
|
+
p1.to_vertex(renderer)
|
|
130
|
+
p2.to_vertex(renderer)
|
|
131
|
+
p3.to_vertex(renderer)
|
|
131
132
|
else
|
|
132
133
|
# Calculate the mid points of this triangle.
|
|
133
134
|
v1 = (p1 + p2) * 0.5
|
|
134
135
|
v2 = (p2 + p3) * 0.5
|
|
135
136
|
v3 = (p3 + p1) * 0.5
|
|
136
|
-
unless (r == 0.0)
|
|
137
|
+
unless (r == 0.0)
|
|
137
138
|
# Project the verticies out onto the sphere with radius r.
|
|
138
139
|
v1.normalize!
|
|
139
140
|
v1 *= r
|
|
@@ -150,9 +151,5 @@ def draw_triangle(depth, r, p1, p2, p3)
|
|
|
150
151
|
# Uncomment out the next line to include the central part of the triangle.
|
|
151
152
|
# draw_triangle(depth, r, v1, v2, v3)
|
|
152
153
|
end
|
|
153
|
-
|
|
154
154
|
end
|
|
155
155
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
@@ -26,17 +26,17 @@ def initialize_cells
|
|
|
26
26
|
n.times do |i|
|
|
27
27
|
a = i + rand(PI / 9.0)
|
|
28
28
|
r = ((i / n.to_f) * (width / 2) * (((n - i) / n.to_f) * 3.3)) + rand(6.0)
|
|
29
|
-
cells << Cell.new((r * cos(a) + width/2).to_i, (r * sin(a) + height/2).to_i)
|
|
29
|
+
cells << Cell.new((r * cos(a) + width / 2).to_i, (r * sin(a) + height / 2).to_i)
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
def start_cell_updates
|
|
34
|
-
Thread.new { Kernel.loop { cells.each {|cell| cell.update } } }
|
|
34
|
+
Thread.new { Kernel.loop { cells.each { |cell| cell.update } } }
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
def draw
|
|
38
38
|
background 255
|
|
39
|
-
cells.each {|cell| cell.sense } if started?
|
|
39
|
+
cells.each { |cell| cell.sense } if started?
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
def started?
|
|
@@ -44,9 +44,13 @@ def started?
|
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
def mouse_pressed
|
|
47
|
-
cells.each {|cell| cell.reset }
|
|
47
|
+
cells.each { |cell| cell.reset }
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
+
##
|
|
51
|
+
# The cell responds to mouse movement
|
|
52
|
+
##
|
|
53
|
+
|
|
50
54
|
class Cell
|
|
51
55
|
attr_reader :x, :y, :spin, :angle
|
|
52
56
|
def initialize(x, y)
|
|
@@ -71,5 +75,4 @@ class Cell
|
|
|
71
75
|
d = LINE_LENGTH * spin + 0.001
|
|
72
76
|
line(x, y, x + d * cos(angle), y + d * sin(angle))
|
|
73
77
|
end
|
|
74
|
-
|
|
75
78
|
end
|
|
@@ -9,23 +9,18 @@
|
|
|
9
9
|
#
|
|
10
10
|
|
|
11
11
|
load_library :vecmath
|
|
12
|
-
import "arcball"
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
Z = 2
|
|
13
|
+
PHI = (sqrt(5) + 1) / 2 - 1 # golden ratio
|
|
14
|
+
GA = PHI * TAU # golden angle
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
GA = PHI * TWO_PI # golden angle
|
|
20
|
-
|
|
21
|
-
KMAX_POINTS = 100000
|
|
16
|
+
KMAX_POINTS = 100_000
|
|
22
17
|
|
|
23
18
|
attr_reader :pts, :rotation_x, :rotation_y, :nbr_points, :radius, :add_points
|
|
24
19
|
attr_reader :my_ball # for arcball rotation
|
|
25
20
|
|
|
26
21
|
def setup
|
|
27
22
|
size(1024, 768, P3D)
|
|
28
|
-
|
|
23
|
+
ArcBall.init(self, width / 2.0, height / 2.0)
|
|
29
24
|
@rotation_x = 0
|
|
30
25
|
@rotation_y = 0
|
|
31
26
|
@nbr_points = 2000
|
|
@@ -47,41 +42,10 @@ def draw
|
|
|
47
42
|
lights
|
|
48
43
|
ambient(200, 10, 10)
|
|
49
44
|
ambient_light(150, 150, 150)
|
|
50
|
-
translate(width/2.0, height/2.0, 0)
|
|
51
|
-
update # for arcball rotation
|
|
52
45
|
render_globe
|
|
53
46
|
end
|
|
54
47
|
|
|
55
|
-
# arcball functionality ##################
|
|
56
|
-
##########################################
|
|
57
|
-
|
|
58
|
-
def update
|
|
59
|
-
theta, x, y, z = my_ball.update
|
|
60
|
-
rotate(theta, x, y, z)
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def mouse_pressed
|
|
64
|
-
my_ball.mouse_pressed(mouse_x, mouse_y)
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def mouse_dragged
|
|
68
|
-
my_ball.mouse_dragged(mouse_x, mouse_y)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def key_pressed
|
|
72
|
-
case(key)
|
|
73
|
-
when 'x'
|
|
74
|
-
my_ball.select_axis(X)
|
|
75
|
-
when 'y'
|
|
76
|
-
my_ball.select_axis(Y)
|
|
77
|
-
when 'z'
|
|
78
|
-
my_ball.select_axis(Z)
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
48
|
|
|
82
|
-
def key_released
|
|
83
|
-
my_ball.select_axis(-1)
|
|
84
|
-
end
|
|
85
49
|
###########################################
|
|
86
50
|
# For Fibonacci Sphere
|
|
87
51
|
##################################
|
|
@@ -106,20 +70,17 @@ def mouse_clicked
|
|
|
106
70
|
@add_points = !add_points
|
|
107
71
|
end
|
|
108
72
|
|
|
109
|
-
SpherePoint = Struct.new(:lat, :lon)
|
|
110
|
-
end
|
|
73
|
+
SpherePoint = Struct.new(:lat, :lon)
|
|
111
74
|
|
|
112
75
|
def init_sphere(num)
|
|
113
76
|
(0 .. num).each do |i|
|
|
114
77
|
lon = GA * i
|
|
115
|
-
lon /= TAU
|
|
116
|
-
lon -= lon.floor
|
|
117
|
-
lon *= TAU
|
|
118
|
-
if
|
|
119
|
-
lon -= TAU
|
|
120
|
-
end
|
|
78
|
+
lon /= TAU
|
|
79
|
+
lon -= lon.floor
|
|
80
|
+
lon *= TAU
|
|
81
|
+
lon -= TAU if lon > PI
|
|
121
82
|
# Convert dome height (which is proportional to surface area) to latitude
|
|
122
|
-
# lat = asin(-1 + 2 * i / num.to_f)
|
|
83
|
+
# lat = asin(-1 + 2 * i / num.to_f)
|
|
123
84
|
pts[i] = SpherePoint.new(asin(-1 + 2 * i / num.to_f), lon)
|
|
124
85
|
end
|
|
125
86
|
end
|
|
@@ -3,13 +3,15 @@
|
|
|
3
3
|
# http://www.contextfreeart.org/gallery/view.php?id=2844
|
|
4
4
|
#
|
|
5
5
|
|
|
6
|
+
load_library :fastmath
|
|
7
|
+
|
|
6
8
|
CMIN = -2.0 # Important to specify float else get random int from range?
|
|
7
9
|
CMAX = 2.0
|
|
8
10
|
FUZZ = 0.04
|
|
9
11
|
SZ = 5
|
|
10
12
|
|
|
11
13
|
def setup
|
|
12
|
-
size 600, 600
|
|
14
|
+
size 600, 600
|
|
13
15
|
no_stroke
|
|
14
16
|
color_mode(HSB, 1.0)
|
|
15
17
|
background(0)
|
|
@@ -17,19 +19,18 @@ def setup
|
|
|
17
19
|
end
|
|
18
20
|
|
|
19
21
|
def draw
|
|
20
|
-
translate(width/2, height/2)
|
|
21
|
-
dot(rand(-
|
|
22
|
+
translate(width / 2, height / 2)
|
|
23
|
+
dot(rand(-180 .. 180), rand(-180 .. 180), rand(CMIN .. CMAX)) unless frame_count > 200_000
|
|
22
24
|
end
|
|
23
25
|
|
|
24
|
-
def dot(px, py, c)
|
|
25
|
-
func = sin(px) + sin(py) + c
|
|
26
|
+
def dot(px, py, c)
|
|
27
|
+
func = DegLut.sin(px) + DegLut.sin(py) + c
|
|
26
28
|
# change function to change the graph eg.
|
|
27
|
-
#func =
|
|
28
|
-
#func = cos(px) + sin(py) + c
|
|
29
|
+
# func = DegLut.cos(px) + DegLut.sin(py) + c
|
|
29
30
|
if func.abs <= FUZZ
|
|
30
31
|
fill(((CMIN - c) / (CMIN - CMAX)), 1, 1)
|
|
31
|
-
ellipse px * width /
|
|
32
|
+
ellipse px * width / 360, py * height / 360, SZ, SZ
|
|
32
33
|
else
|
|
33
|
-
dot(rand(-
|
|
34
|
+
dot(rand(-180 .. 180), rand(-180 .. 180), rand(CMIN .. CMAX))
|
|
34
35
|
end
|
|
35
36
|
end
|
|
@@ -7,7 +7,7 @@ def setup
|
|
|
7
7
|
@particles = []
|
|
8
8
|
@grabbed = nil
|
|
9
9
|
background 0
|
|
10
|
-
smooth
|
|
10
|
+
smooth 4
|
|
11
11
|
stroke_weight 4
|
|
12
12
|
ellipse_mode CENTER
|
|
13
13
|
color_mode RGB, 255
|
|
@@ -17,13 +17,13 @@ def draw
|
|
|
17
17
|
no_stroke
|
|
18
18
|
fill 0, 60
|
|
19
19
|
rect 0, 0, width, height
|
|
20
|
-
particles.each {|p| p.collect_force; p.move; p.render }
|
|
20
|
+
particles.each { |p| p.collect_force; p.move; p.render }
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def mouse_pressed
|
|
24
24
|
return if mouse_x == 0 || mouse_y == 0
|
|
25
25
|
return if particle_grab
|
|
26
|
-
particles << Particle.new(mouse_x, mouse_y, rand
|
|
26
|
+
particles << Particle.new(mouse_x, mouse_y, rand(0.1 .. 8))
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def mouse_released
|
|
@@ -31,14 +31,11 @@ def mouse_released
|
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
def particle_grab
|
|
34
|
-
@grabbed = particles.detect {|p| dist(mouse_x, mouse_y, p.x1, p.y1) < p.diameter/2 }
|
|
34
|
+
@grabbed = particles.detect { |p| dist(mouse_x, mouse_y, p.x1, p.y1) < p.diameter/2 }
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
|
|
38
37
|
class Particle
|
|
39
|
-
|
|
40
|
-
GRAVITY = 1.0
|
|
41
|
-
|
|
38
|
+
GRAVITY = 1.0
|
|
42
39
|
attr_reader :x0, :y0, :x1, :y1, :diameter, :mass_amount
|
|
43
40
|
|
|
44
41
|
def initialize(x, y, mass)
|
|
@@ -54,8 +51,8 @@ class Particle
|
|
|
54
51
|
@min_dist = 1000
|
|
55
52
|
$app.particles.each do |p|
|
|
56
53
|
next if p == self
|
|
57
|
-
g_dist =
|
|
58
|
-
g_theta = -(
|
|
54
|
+
g_dist = Math.hypot(x0 - p.x0, y0 - p.y0)
|
|
55
|
+
g_theta = -angle_of(x0, y0, p.x0, p.y0)
|
|
59
56
|
@min_dist = g_dist if g_dist < @min_dist
|
|
60
57
|
force = (GRAVITY * mass_amount * p.mass_amount) / g_dist
|
|
61
58
|
if g_dist.abs > diameter
|
|
@@ -84,7 +81,7 @@ class Particle
|
|
|
84
81
|
def render_free
|
|
85
82
|
charge_col = 1000.0 / @min_dist / 50.0
|
|
86
83
|
tot_col_1 = 100 + charge_col * 6
|
|
87
|
-
tot_col_2 = 150 + charge_col*charge_col
|
|
84
|
+
tot_col_2 = 150 + charge_col * charge_col
|
|
88
85
|
tot_col_3 = diameter + 8 + charge_col
|
|
89
86
|
fill(tot_col_1, tot_col_1, 255, charge_col * 150 + 3)
|
|
90
87
|
ellipse(x1, y1, tot_col_3, tot_col_3)
|
|
@@ -103,9 +100,7 @@ class Particle
|
|
|
103
100
|
@x0, @y0 = mouse_x, mouse_y
|
|
104
101
|
end
|
|
105
102
|
|
|
106
|
-
def
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
end
|
|
110
|
-
|
|
103
|
+
def angle_of(x1, y1, x2, y2)
|
|
104
|
+
Math::PI - atan2(y1 - y2, x1 - x2)
|
|
105
|
+
end
|
|
111
106
|
end
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
# from a Python example for Nodebox, and then, now
|
|
4
4
|
# to Ruby-Processing.
|
|
5
5
|
|
|
6
|
-
# For fun, try running it via jirb, and
|
|
7
|
-
# playing with the attr_accessors, as
|
|
6
|
+
# For fun, try running it via jirb, and
|
|
7
|
+
# playing with the attr_accessors, as
|
|
8
8
|
# well as the background.
|
|
9
9
|
|
|
10
10
|
# This example now demonstrates the use of the control_panel.
|
|
@@ -13,21 +13,20 @@
|
|
|
13
13
|
|
|
14
14
|
load_library :control_panel
|
|
15
15
|
|
|
16
|
-
attr_accessor :x_wiggle, :y_wiggle, :magnitude, :bluish, :panel, :laf, :hide
|
|
16
|
+
attr_accessor :x_wiggle, :y_wiggle, :magnitude, :bluish, :panel, :laf, :hide
|
|
17
17
|
|
|
18
18
|
def setup
|
|
19
|
-
size 600, 600
|
|
19
|
+
size 600, 600
|
|
20
20
|
control_panel do |c|
|
|
21
|
-
c.look_feel
|
|
21
|
+
c.look_feel 'Nimbus'
|
|
22
22
|
c.slider :bluish, 0.0..1.0, 0.5
|
|
23
23
|
c.slider :alpha, 0.0..1.0, 0.5
|
|
24
24
|
c.checkbox :go_big
|
|
25
25
|
c.button :reset
|
|
26
|
-
c.menu :shape,
|
|
26
|
+
c.menu :shape, %w(oval square)
|
|
27
27
|
@panel = c
|
|
28
28
|
end
|
|
29
29
|
@hide = false
|
|
30
|
-
|
|
31
30
|
@shape = 'oval'
|
|
32
31
|
@alpha, @bluish = 0.5, 0.5
|
|
33
32
|
@x_wiggle, @y_wiggle = 10.0, 0
|
|
@@ -45,7 +44,7 @@ end
|
|
|
45
44
|
|
|
46
45
|
def draw_background
|
|
47
46
|
@background[3] = @alpha
|
|
48
|
-
fill
|
|
47
|
+
fill(*@background) if @background[0]
|
|
49
48
|
rect 0, 0, width, height
|
|
50
49
|
end
|
|
51
50
|
|
|
@@ -57,38 +56,37 @@ def draw
|
|
|
57
56
|
# only make control_panel visible once, or again when hide is false
|
|
58
57
|
unless hide
|
|
59
58
|
@hide = true
|
|
60
|
-
panel.
|
|
59
|
+
panel.set_visible(hide)
|
|
61
60
|
end
|
|
62
61
|
draw_background
|
|
63
|
-
|
|
62
|
+
|
|
64
63
|
# Seed the random numbers for consistent placement from frame to frame
|
|
65
64
|
srand(0)
|
|
66
65
|
horiz, vert, mag = @x_wiggle, @y_wiggle, @magnitude
|
|
67
|
-
|
|
66
|
+
|
|
68
67
|
if @go_big
|
|
69
68
|
mag *= 2
|
|
70
69
|
vert /= 2
|
|
71
70
|
end
|
|
72
|
-
|
|
71
|
+
|
|
73
72
|
blu = bluish
|
|
74
|
-
x, y = (
|
|
73
|
+
x, y = (width / 2), -27
|
|
75
74
|
c = 0.0
|
|
76
|
-
|
|
77
|
-
64.times do
|
|
78
|
-
x += cos(horiz)*mag
|
|
79
|
-
y += log10(vert)*mag + sin(vert) * 2
|
|
75
|
+
|
|
76
|
+
64.times do
|
|
77
|
+
x += cos(horiz) * mag
|
|
78
|
+
y += log10(vert) * mag + sin(vert) * 2
|
|
80
79
|
fill(sin(@y_wiggle + c), rand * 0.2, rand * blu, 0.5)
|
|
81
80
|
s = 42 + cos(vert) * 17
|
|
82
|
-
args = [x-s/2, y-s/2, s, s]
|
|
81
|
+
args = [x - s / 2, y - s / 2, s, s]
|
|
83
82
|
@shape == 'oval' ? oval(*args) : rect(*args)
|
|
84
83
|
vert += rand * 0.25
|
|
85
84
|
horiz += rand * 0.25
|
|
86
85
|
c += 0.1
|
|
87
86
|
end
|
|
88
|
-
|
|
87
|
+
|
|
89
88
|
@x_wiggle += 0.05
|
|
90
89
|
@y_wiggle += 0.1
|
|
91
|
-
|
|
92
90
|
end
|
|
93
91
|
|
|
94
92
|
def mouse_pressed
|