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
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
# Particles are generated each cycle, fall with gravity and fade out over
|
|
4
4
|
# time. A ParticleSystem (Array) object manages a variable size list of
|
|
5
5
|
# particles.
|
|
6
|
+
require 'forwardable'
|
|
7
|
+
|
|
6
8
|
load_library :vecmath
|
|
7
9
|
|
|
8
10
|
attr_reader :ps
|
|
@@ -26,30 +28,24 @@ module Runnable
|
|
|
26
28
|
end
|
|
27
29
|
|
|
28
30
|
class ParticleSystem
|
|
29
|
-
extend
|
|
31
|
+
extend Forwardable
|
|
32
|
+
def_delegators(:@particle_system, :each, :<<, :reject!, :empty?)
|
|
33
|
+
include Enumerable
|
|
30
34
|
include Runnable
|
|
31
35
|
|
|
32
|
-
attr_reader :origin
|
|
36
|
+
attr_reader :origin
|
|
33
37
|
|
|
34
38
|
def initialize(loc)
|
|
35
39
|
@particle_system = []
|
|
36
40
|
@origin = Vec2D.new(loc.x, loc.y)
|
|
37
41
|
end
|
|
38
42
|
|
|
39
|
-
def each &block
|
|
40
|
-
particle_system.each &block
|
|
41
|
-
end
|
|
42
|
-
|
|
43
43
|
def add_particle
|
|
44
|
-
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def reject! &block
|
|
48
|
-
particle_system.reject! &block
|
|
44
|
+
self << Particle.new(origin)
|
|
49
45
|
end
|
|
50
46
|
|
|
51
47
|
def dead?
|
|
52
|
-
|
|
48
|
+
self.empty?
|
|
53
49
|
end
|
|
54
50
|
|
|
55
51
|
end
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
#
|
|
4
4
|
# A ParticleSystem (Array) object manages a variable size list of
|
|
5
5
|
# particles.
|
|
6
|
-
|
|
6
|
+
require 'forwardable'
|
|
7
|
+
|
|
7
8
|
load_library :vecmath
|
|
8
9
|
|
|
9
10
|
attr_reader :ps, :img, :wind
|
|
@@ -26,7 +27,7 @@ def draw
|
|
|
26
27
|
end
|
|
27
28
|
|
|
28
29
|
# Draw a horizontal arrow representing the wind force
|
|
29
|
-
draw_vector(wind, Vec2D.new(width / 2, 50
|
|
30
|
+
draw_vector(wind, Vec2D.new(width / 2, 50), 500)
|
|
30
31
|
|
|
31
32
|
end
|
|
32
33
|
|
|
@@ -58,10 +59,12 @@ end
|
|
|
58
59
|
|
|
59
60
|
|
|
60
61
|
class ParticleSystem
|
|
61
|
-
extend
|
|
62
|
+
extend Forwardable
|
|
63
|
+
def_delegators(:@particles, :reject!, :<<, :each)
|
|
64
|
+
include Enumerable
|
|
62
65
|
include Runnable
|
|
63
66
|
|
|
64
|
-
attr_reader :
|
|
67
|
+
attr_reader :origin, :image, :generator
|
|
65
68
|
|
|
66
69
|
def initialize(num, location, image)
|
|
67
70
|
@particles = []
|
|
@@ -72,16 +75,8 @@ class ParticleSystem
|
|
|
72
75
|
end
|
|
73
76
|
end
|
|
74
77
|
|
|
75
|
-
def each &block
|
|
76
|
-
particles.each &block
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def reject! &block
|
|
80
|
-
particles.reject! &block
|
|
81
|
-
end
|
|
82
|
-
|
|
83
78
|
def add_particle(p = Particle.new(origin, image))
|
|
84
|
-
|
|
79
|
+
self << p
|
|
85
80
|
end
|
|
86
81
|
|
|
87
82
|
# Method to add a force vector to all particles currently in the system
|
|
File without changes
|
data/samples/processing_app/library/vecmath/{library/wiggler/wiggler.rb → vec2d/wiggle_pshape.rb}
RENAMED
|
@@ -1,32 +1,55 @@
|
|
|
1
|
+
#
|
|
2
|
+
# WigglePShape. Demonstrates initialization and use of ShapeRender,
|
|
3
|
+
# that allows us to send Vec2D to PShape vertex
|
|
4
|
+
#
|
|
5
|
+
# How to move the individual vertices of a PShape
|
|
6
|
+
#
|
|
7
|
+
load_library :vecmath
|
|
8
|
+
|
|
9
|
+
attr_reader :wiggler
|
|
10
|
+
|
|
11
|
+
def setup
|
|
12
|
+
size(640, 360, P2D)
|
|
13
|
+
@wiggler = Wiggler.new width, height
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def draw
|
|
17
|
+
background(255)
|
|
18
|
+
wiggler.display
|
|
19
|
+
wiggler.wiggle
|
|
20
|
+
end
|
|
21
|
+
|
|
1
22
|
# An object that wraps the PShape
|
|
2
23
|
|
|
3
24
|
|
|
4
25
|
class Wiggler
|
|
5
26
|
include Processing::Proxy
|
|
6
|
-
attr_reader :original, :x, :y, :s, :yoff, :xoff
|
|
27
|
+
attr_reader :original, :x, :y, :s, :yoff, :xoff, :renderer
|
|
7
28
|
|
|
8
29
|
def initialize width, height
|
|
9
30
|
@x = width/2
|
|
10
31
|
@y = height/2
|
|
11
32
|
@yoff = 0
|
|
33
|
+
|
|
12
34
|
# The "original" locations of the vertices make up a circle
|
|
13
35
|
|
|
14
|
-
@original = (0 ...
|
|
36
|
+
@original = (0 ... 16).map{|a| Vec2D.from_angle(PI * a / 8) * 100}
|
|
15
37
|
|
|
16
38
|
# Now make the PShape with those vertices
|
|
17
39
|
@s = create_shape
|
|
40
|
+
@renderer = ShapeRender.new(s)
|
|
18
41
|
s.begin_shape
|
|
19
42
|
s.fill(127)
|
|
20
43
|
s.stroke(0)
|
|
21
44
|
s.stroke_weight(2)
|
|
22
|
-
original.map{
|
|
45
|
+
original.map{|v| v.to_vertex(renderer)}
|
|
23
46
|
s.end_shape(CLOSE)
|
|
24
47
|
end
|
|
25
48
|
|
|
26
49
|
def wiggle
|
|
27
50
|
@xoff = 0
|
|
28
51
|
# Apply an offset to each vertex
|
|
29
|
-
rad = ->
|
|
52
|
+
rad = ->(pos){(Vec2D.from_angle(TAU * noise(xoff, yoff)) * 4) + pos}
|
|
30
53
|
|
|
31
54
|
original.each_with_index do |pos, i|
|
|
32
55
|
# Calculate a new vertex location based on noise around "original" location
|
|
@@ -48,3 +71,4 @@ class Wiggler
|
|
|
48
71
|
end
|
|
49
72
|
end
|
|
50
73
|
|
|
74
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Simple demo Rakefile to autorun samples in current directory
|
|
2
|
+
# adjust path to rp5 executable, and or opts as required
|
|
3
|
+
|
|
4
|
+
SAMPLES_DIR = './'
|
|
5
|
+
|
|
6
|
+
desc 'run demo'
|
|
7
|
+
task default: [:demo]
|
|
8
|
+
|
|
9
|
+
desc 'demo'
|
|
10
|
+
task :demo do
|
|
11
|
+
samples_list.shuffle.each{ |sample| run_sample sample }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def samples_list
|
|
15
|
+
files = []
|
|
16
|
+
Dir.chdir(SAMPLES_DIR)
|
|
17
|
+
Dir.glob('*.rb').each do |file|
|
|
18
|
+
files << File.join(SAMPLES_DIR, file)
|
|
19
|
+
end
|
|
20
|
+
return files
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def run_sample(sample_name)
|
|
24
|
+
puts "Running #{sample_name}...quit to run next sample"
|
|
25
|
+
open("|rp5 run #{sample_name}", 'r') do |io|
|
|
26
|
+
while l = io.gets
|
|
27
|
+
puts(l.chop)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Drawolver: draw 2D & revolve 3D
|
|
2
|
+
|
|
3
|
+
# Example shows how to use the vecmath library, including AppRender utility.
|
|
4
|
+
# On the ruby side features the use each_cons, a possibly a rare use for this
|
|
5
|
+
# ruby Enumerable method?
|
|
6
|
+
# 2010-03-22 - fjenett (somewhat revised by Martin Prout 2014-07-06)
|
|
7
|
+
|
|
8
|
+
load_library :vecmath, :fastmath
|
|
9
|
+
|
|
10
|
+
attr_reader :drawing_mode, :points, :rot_x, :rot_y, :vertices, :renderer
|
|
11
|
+
|
|
12
|
+
def setup
|
|
13
|
+
size 1024, 768, P3D
|
|
14
|
+
@renderer = AppRender.new(self)
|
|
15
|
+
frame_rate 30
|
|
16
|
+
reset_scene
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def draw
|
|
20
|
+
background 0
|
|
21
|
+
unless drawing_mode
|
|
22
|
+
translate(width / 2, height / 2)
|
|
23
|
+
rotate_x rot_x
|
|
24
|
+
rotate_y rot_y
|
|
25
|
+
@rot_x += 0.01
|
|
26
|
+
@rot_y += 0.02
|
|
27
|
+
translate(-width / 2, -height / 2)
|
|
28
|
+
end
|
|
29
|
+
no_fill
|
|
30
|
+
stroke 255
|
|
31
|
+
points.each_cons(2) { |ps, pe| line ps.x, ps.y, pe.x, pe.y }
|
|
32
|
+
unless drawing_mode
|
|
33
|
+
stroke 125
|
|
34
|
+
fill 120
|
|
35
|
+
lights
|
|
36
|
+
ambient_light 120, 120, 120
|
|
37
|
+
vertices.each_cons(2) do |r1, r2|
|
|
38
|
+
begin_shape(TRIANGLE_STRIP)
|
|
39
|
+
r1.zip(r2).each do |v1, v2|
|
|
40
|
+
v1.to_vertex(renderer)
|
|
41
|
+
v2.to_vertex(renderer)
|
|
42
|
+
end
|
|
43
|
+
end_shape
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def reset_scene
|
|
49
|
+
@drawing_mode = true
|
|
50
|
+
@points = []
|
|
51
|
+
@rot_x = 0.0
|
|
52
|
+
@rot_y = 0.0
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def mouse_pressed
|
|
56
|
+
reset_scene
|
|
57
|
+
points << Vec3D.new(mouse_x, mouse_y)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def mouse_dragged
|
|
61
|
+
points << Vec3D.new(mouse_x, mouse_y)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def mouse_released
|
|
65
|
+
points << Vec3D.new(mouse_x, mouse_y)
|
|
66
|
+
recalculate_shape
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def recalculate_shape
|
|
70
|
+
@vertices = []
|
|
71
|
+
points.each_cons(2) do |ps, _pe_|
|
|
72
|
+
b = (points.last - points.first).normalize!
|
|
73
|
+
a = ps - points.first
|
|
74
|
+
dot_product = a.dot b
|
|
75
|
+
b *= dot_product
|
|
76
|
+
normal = points.first + b
|
|
77
|
+
c = ps - normal
|
|
78
|
+
vertices << []
|
|
79
|
+
(0..360).step(12) do |ang|
|
|
80
|
+
e = normal + c * DegLut.cos(ang)
|
|
81
|
+
e.z = c.mag * DegLut.sin(ang)
|
|
82
|
+
vertices.last << e
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
@drawing_mode = false
|
|
86
|
+
end
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
###############
|
|
2
|
+
# Frame of Reference example by Ira Greenberg
|
|
3
|
+
# https://github.com/irajgreenberg/ProcessingTips
|
|
4
|
+
# Translated to ruby-processing by Martin Prout January 2014
|
|
5
|
+
###############
|
|
6
|
+
|
|
7
|
+
load_libraries :fastmath, :vecmath
|
|
8
|
+
load_library :geometry
|
|
9
|
+
|
|
10
|
+
FACE_COUNT = 50
|
|
11
|
+
|
|
12
|
+
attr_reader :c, :p, :renderer
|
|
13
|
+
|
|
14
|
+
def setup
|
|
15
|
+
size(800, 800, P3D)
|
|
16
|
+
ArcBall.init(self, width / 2.0, height / 2.0) # user supplied center
|
|
17
|
+
@renderer = AppRender.new(self)
|
|
18
|
+
@c = []
|
|
19
|
+
@p = []
|
|
20
|
+
FACE_COUNT.times do |i|
|
|
21
|
+
|
|
22
|
+
# calc some random triangles in 3 space
|
|
23
|
+
val = Vec3D.new(rand(-width/2 .. width/2), rand(-width/2 .. width/2), rand(-width/2 .. width/2))
|
|
24
|
+
v0 = Vec3D.new(rand(-val.x .. -val.x + 100), rand(-val.y .. -val.y + 100), rand(-val.z .. -val.z + 100))
|
|
25
|
+
v1 = Vec3D.new(rand(-val.x .. -val.x + 100), rand(-val.y .. -val.y + 100), rand(-val.z .. -val.z + 100))
|
|
26
|
+
v2 = Vec3D.new(rand(-val.x .. -val.x + 100), rand(-val.y .. -val.y + 100), rand(-val.z .. -val.z + 100))
|
|
27
|
+
p << Plane.new([v0, v1, v2])
|
|
28
|
+
|
|
29
|
+
# build some cute little cylinders
|
|
30
|
+
c << Cylinder.new(Vec3D.new(150, 5, 5), 12)
|
|
31
|
+
|
|
32
|
+
# Using each Triangle normal (N),
|
|
33
|
+
# One of the Triangle's edges as a tangent (T)
|
|
34
|
+
# Calculate a bi-normal (B) using the cross-product between each N and T
|
|
35
|
+
# Note caps represent constants in ruby so we used N = nn, T = tt and B = bb in the ruby code below
|
|
36
|
+
|
|
37
|
+
#
|
|
38
|
+
# A picture helps
|
|
39
|
+
# nice, sweet orthogonal axes
|
|
40
|
+
|
|
41
|
+
# N B
|
|
42
|
+
# | /
|
|
43
|
+
# | /
|
|
44
|
+
# |/____T
|
|
45
|
+
|
|
46
|
+
#
|
|
47
|
+
# N, T, B together give you a Frame of Reference (cute little local coordinate system), based on each triangle.
|
|
48
|
+
# You can then take the cylinder (or any vertices) and transform them using a 3 x 3 matrix to this coordinate system.
|
|
49
|
+
# (In the matrix each column is based on N, T and B respecivley.)
|
|
50
|
+
# The transform will handle any rotations and scaling, but not the translation,
|
|
51
|
+
# but we can add another dimenson to the matrix to hold the translation values.
|
|
52
|
+
# Here's what all this confusing description looks like:
|
|
53
|
+
|
|
54
|
+
#
|
|
55
|
+
# Matrix : Vector :
|
|
56
|
+
# | N.x T.x B.x translation.x | | x |
|
|
57
|
+
# | N.y T.y B.y translation.y | | y |
|
|
58
|
+
# | N.z T.z B.z translation.z | | z |
|
|
59
|
+
# | 0 0 0 1 | | 1 |
|
|
60
|
+
|
|
61
|
+
# We add the extra row in the matrix and the 1 to each vector
|
|
62
|
+
# so the math works. We describe the Matrix as 4 rows by 4 columns
|
|
63
|
+
# and the vector now as a Matrix with 4 rows and 1 column.
|
|
64
|
+
# When you multiply matrices the inner numbers MUST match, so:
|
|
65
|
+
# [4 x 4] [4 x 1] is OK, but [4 x 4] [1 x 4] is NOT COOL.
|
|
66
|
+
|
|
67
|
+
# (Please note there is also row vector approach that you can
|
|
68
|
+
# Google about; it simply puts the vector on left side of matrix and treats
|
|
69
|
+
# it as a 1 row and 4 column matrix. However, you'll also need to shift
|
|
70
|
+
# the translation terms to the bottom of the matrix for the math to grock.)
|
|
71
|
+
|
|
72
|
+
# The Matrix multiplication looks like this (sorry it's a little tedious looking.)
|
|
73
|
+
# n.x * x + t.x *y + B.x * z + translation.x * 1 = new transformed x
|
|
74
|
+
# n.y * x + t.y *y + B.y * z + translation.y * 1 = new transformed y
|
|
75
|
+
# n.z * x + t.z *y + B.z * z + translation.z * 1 = new transformed z
|
|
76
|
+
# 0 * x + 0 *y + 0 * z + 1 * 1 = disregard this crap.
|
|
77
|
+
#
|
|
78
|
+
|
|
79
|
+
nn = p[i].n
|
|
80
|
+
tt = Vec3D.new(p[i].vecs[1].x - p[i].vecs[0].x, p[i].vecs[1].y - p[i].vecs[0].y, p[i].vecs[1].z - p[i].vecs[0].z)
|
|
81
|
+
nn.normalize!
|
|
82
|
+
tt.normalize!
|
|
83
|
+
bb = nn.cross(tt)
|
|
84
|
+
bb.normalize! # not really needed
|
|
85
|
+
|
|
86
|
+
# build matrix with frame and translation (to centroid of each triangle)
|
|
87
|
+
m4 = Mat4.new(nn, tt, bb, p[i].c)
|
|
88
|
+
|
|
89
|
+
# transform each cylinder to align with each triangle
|
|
90
|
+
c[i].vecs = m4.mult(c[i].vecs)
|
|
91
|
+
end
|
|
92
|
+
fill(187)
|
|
93
|
+
stroke(50, 20)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def draw
|
|
97
|
+
background(0)
|
|
98
|
+
lights
|
|
99
|
+
FACE_COUNT.times do |i|
|
|
100
|
+
p[i].display(renderer)
|
|
101
|
+
c[i].display(renderer)
|
|
102
|
+
end
|
|
103
|
+
end
|
|
@@ -3,42 +3,27 @@
|
|
|
3
3
|
# Lindenmayer System in ruby-processing by Martin Prout
|
|
4
4
|
# Demonstrates arcball rotation hold down z, y or z key
|
|
5
5
|
# to constrain to that axis of rotation. Otherwise get
|
|
6
|
-
# intuitive rotation
|
|
6
|
+
# intuitive rotation using mouse drag.
|
|
7
7
|
########################################################
|
|
8
8
|
|
|
9
9
|
load_libraries :hilbert, :vecmath
|
|
10
10
|
|
|
11
|
-
attr_reader :hilbert, :
|
|
11
|
+
attr_reader :hilbert, :renderer
|
|
12
12
|
|
|
13
13
|
def setup
|
|
14
14
|
size 1024, 768, P3D
|
|
15
|
-
|
|
16
|
-
@hilbert = Hilbert.new(size: height/2, gen: 3)
|
|
15
|
+
ArcBall.init(self, width / 2.0, height / 2.0)
|
|
16
|
+
@hilbert = Hilbert.new(size: height / 2, gen: 3)
|
|
17
17
|
no_stroke
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
def draw
|
|
21
21
|
background 0
|
|
22
|
-
translate(width/2.0, height/2.0)
|
|
23
|
-
update
|
|
24
22
|
lights
|
|
25
23
|
define_lights
|
|
26
24
|
ambient(40)
|
|
27
25
|
specular(15)
|
|
28
|
-
hilbert.
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def update
|
|
32
|
-
theta, x, y, z = arcball.update
|
|
33
|
-
rotate(theta, x, y, z)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def mouse_pressed
|
|
37
|
-
arcball.mouse_pressed(mouse_x, mouse_y)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def mouse_dragged
|
|
41
|
-
arcball.mouse_dragged(mouse_x, mouse_y)
|
|
26
|
+
hilbert.draw
|
|
42
27
|
end
|
|
43
28
|
|
|
44
29
|
def define_lights
|
|
@@ -49,17 +34,4 @@ def define_lights
|
|
|
49
34
|
spot_light(30, 30, 30, 0, 40, 200, 0, -0.5, 0.5, PI / 2, 2)
|
|
50
35
|
end
|
|
51
36
|
|
|
52
|
-
def key_pressed
|
|
53
|
-
case(key)
|
|
54
|
-
when 'x'
|
|
55
|
-
arcball.select_axis(X)
|
|
56
|
-
when 'y'
|
|
57
|
-
arcball.select_axis(Y)
|
|
58
|
-
when 'z'
|
|
59
|
-
arcball.select_axis(Z)
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
37
|
|
|
63
|
-
def key_released
|
|
64
|
-
arcball.select_axis(-1)
|
|
65
|
-
end
|