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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Drawolver: draw 2D & revolve 3D
|
|
2
2
|
|
|
3
3
|
# Example to show how to use the VecMath library.
|
|
4
|
-
# Also the Array is extended to yield one_of_each
|
|
4
|
+
# Also the Array is extended to yield one_of_each using a module
|
|
5
5
|
# pair of pts. See the drawolver library. Also features the use each_cons,
|
|
6
6
|
# possibly a rare use for this ruby Enumerable method?
|
|
7
7
|
# 2010-03-22 - fjenett (last revised by monkstone 2013-09-13)
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
# But there are two ways to define methods with variable parameters. One is to give the
|
|
15
15
|
# parameters a default value, the second is to use the catch-all asterix:
|
|
16
16
|
|
|
17
|
+
|
|
17
18
|
# def my_method1 ( a, b = "2" ) # can be called with one or two arguments
|
|
18
19
|
# end
|
|
19
20
|
|
|
@@ -21,6 +22,10 @@
|
|
|
21
22
|
# end
|
|
22
23
|
|
|
23
24
|
|
|
25
|
+
# Martin Prout, 2014-06-23:
|
|
26
|
+
# even more flexibility can be had by passing a hash see inheritance_two @todo update for ruby-2.1+
|
|
27
|
+
|
|
28
|
+
|
|
24
29
|
def setup
|
|
25
30
|
size 640, 360
|
|
26
31
|
background 204
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Storing Data as a Struct
|
|
3
|
+
#
|
|
4
|
+
# Move the mouse across the screen to change the position
|
|
5
|
+
# of the circles. The positions of the mouse are recorded
|
|
6
|
+
# into an array and played back every frame. Between each
|
|
7
|
+
# frame, the newest value are added to the end of each array
|
|
8
|
+
# and the oldest value is deleted.
|
|
9
|
+
#
|
|
10
|
+
|
|
11
|
+
NUM = 60
|
|
12
|
+
|
|
13
|
+
attr_reader :pos
|
|
14
|
+
|
|
15
|
+
Vec = Struct.new(:x, :y) # create named Struct Type with getters and setters
|
|
16
|
+
|
|
17
|
+
def setup
|
|
18
|
+
size(640, 360)
|
|
19
|
+
@pos = Array.new(NUM, Vec.new(0, 0)) # initialize a array of Struct
|
|
20
|
+
smooth(4)
|
|
21
|
+
no_stroke()
|
|
22
|
+
fill(255, 153)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def draw
|
|
26
|
+
background(51)
|
|
27
|
+
|
|
28
|
+
# Cycle through the array, using a different entry on each frame.
|
|
29
|
+
# Using modulo (%) like this is faster than moving all the values over.
|
|
30
|
+
which = frame_count % NUM
|
|
31
|
+
pos[which] = Vec.new(mouse_x, mouse_y)
|
|
32
|
+
|
|
33
|
+
(1 .. NUM).each do |i|
|
|
34
|
+
# which + 1 is the smallest (the oldest in the array)
|
|
35
|
+
idx = (which + i) % NUM
|
|
36
|
+
ellipse(pos[idx].x, pos[idx].y, i, i)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -13,20 +13,17 @@ def setup
|
|
|
13
13
|
size 640, 360, P3D
|
|
14
14
|
no_stroke
|
|
15
15
|
lights
|
|
16
|
-
@birds =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
bird.set_rot_speed rand(0.025 .. 0.15)
|
|
23
|
-
@birds << bird
|
|
24
|
-
end
|
|
16
|
+
@birds = (0 .. BIRD_COUNT).map {
|
|
17
|
+
Bird.new(rand(-300 .. 300), rand(-300 .. 300), rand(-2500 .. -500), rand(5 .. 30), rand(5 .. 30))
|
|
18
|
+
.set_flight(rand(20 .. 340), rand(30 .. 350), rand( 1000 .. 4800 ), rand(-160 .. 160), rand(-55 .. 55), rand(-20 .. 20))
|
|
19
|
+
.set_wing_speed(rand(0.1 .. 3.75))
|
|
20
|
+
.set_rot_speed(rand(0.025 .. 0.15))
|
|
21
|
+
}
|
|
25
22
|
end
|
|
26
23
|
|
|
27
24
|
def draw
|
|
28
25
|
background 0
|
|
29
26
|
translate width/2, height/2, -700
|
|
30
|
-
@birds.
|
|
27
|
+
@birds.map {|b| b.fly}
|
|
31
28
|
end
|
|
32
29
|
|
|
@@ -28,19 +28,19 @@ class Bird
|
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def set_flight ( radius_x, radius_y, radius_z, rot_x, rot_y, rot_z )
|
|
31
|
-
|
|
32
31
|
@radius_x, @radius_y, @radius_z = radius_x, radius_y, radius_z
|
|
33
32
|
@rot_x, @rot_y, @rot_z = rot_x, rot_y, rot_z
|
|
33
|
+
return self # return self means we can chain methods
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
def set_wing_speed ( flap_speed )
|
|
37
|
-
|
|
38
37
|
@flap_speed = flap_speed
|
|
38
|
+
return self # return self means we can chain methods
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
def set_rot_speed ( rot_speed )
|
|
42
|
-
|
|
43
42
|
@rot_speed = rot_speed
|
|
43
|
+
return self # return self means we can chain methods
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
def fly
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
#
|
|
3
3
|
# Rotating a square around the Z axis. To get the results
|
|
4
4
|
# you expect, send the rotate function angle parameters that are
|
|
5
|
-
# values between 0 and PI*2 (
|
|
5
|
+
# values between 0 and PI*2 (TAU which is roughly 6.28). If you prefer to
|
|
6
6
|
# think about angles as degrees (0-360), you can use the radians()
|
|
7
7
|
# method to convert your values. For example: scale(radians(90))
|
|
8
8
|
# is identical to the statement scale(PI/2).
|
|
@@ -19,7 +19,7 @@ attr_accessor :outp, :inp, :normp, :auto_normals, :arcball, :bez_patch
|
|
|
19
19
|
|
|
20
20
|
def setup
|
|
21
21
|
size(1024, 768, P3D)
|
|
22
|
-
|
|
22
|
+
ArcBall.init(self, width/2.0, height/2.0)
|
|
23
23
|
@auto_normals = false
|
|
24
24
|
build_geometry
|
|
25
25
|
@bez_patch = build_shape
|
|
@@ -27,12 +27,10 @@ end
|
|
|
27
27
|
|
|
28
28
|
def draw
|
|
29
29
|
background(255)
|
|
30
|
-
translate(width/2,height/2)
|
|
31
30
|
smooth(8)
|
|
32
31
|
lights
|
|
33
32
|
define_lights
|
|
34
33
|
scale(0.9)
|
|
35
|
-
update
|
|
36
34
|
no_stroke
|
|
37
35
|
shape(bez_patch)
|
|
38
36
|
end
|
|
@@ -169,24 +167,6 @@ def d_bezier_blend( k, mu, n)
|
|
|
169
167
|
return(dblendf)
|
|
170
168
|
end
|
|
171
169
|
|
|
172
|
-
######################
|
|
173
|
-
# ArcBall control
|
|
174
|
-
# and lighting + re-run
|
|
175
|
-
######################
|
|
176
|
-
|
|
177
|
-
def update
|
|
178
|
-
theta, x, y, z = arcball.update
|
|
179
|
-
rotate(theta, x, y, z)
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
def mouse_pressed
|
|
183
|
-
arcball.mouse_pressed(mouse_x, mouse_y)
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
def mouse_dragged
|
|
187
|
-
arcball.mouse_dragged(mouse_x, mouse_y)
|
|
188
|
-
end
|
|
189
|
-
|
|
190
170
|
def define_lights
|
|
191
171
|
ambient_light(40, 40, 40)
|
|
192
172
|
point_light(30, 30, 30, 0, 0, 0)
|
|
@@ -194,21 +174,4 @@ def define_lights
|
|
|
194
174
|
spot_light(30, 30, 30, 0, 40, 200, 0, -0.5, 0.5, PI / 2, 2)
|
|
195
175
|
end
|
|
196
176
|
|
|
197
|
-
def key_pressed
|
|
198
|
-
case(key)
|
|
199
|
-
when ' '
|
|
200
|
-
save_frame("bezPatch.png")
|
|
201
|
-
build_geometry
|
|
202
|
-
@bez_patch = build_shape
|
|
203
|
-
when 'x'
|
|
204
|
-
arcball.select_axis(X)
|
|
205
|
-
when 'y'
|
|
206
|
-
arcball.select_axis(Y)
|
|
207
|
-
when 'z'
|
|
208
|
-
arcball.select_axis(Z)
|
|
209
|
-
end
|
|
210
|
-
end
|
|
211
177
|
|
|
212
|
-
def key_released
|
|
213
|
-
arcball.select_axis(-1)
|
|
214
|
-
end
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
# Trefoil, by Andres Colubri
|
|
2
2
|
# A parametric surface is textured procedurally
|
|
3
3
|
# by drawing on an offscreen PGraphics surface.
|
|
4
|
+
#
|
|
5
|
+
# Features (Vec3D).to_normal(renderer) and (Vec3D).to_vertex_uv(renderer, u, v)
|
|
6
|
+
# see line 62 for inititialization of renderer where obj is an instance of PShape
|
|
7
|
+
# renderer = ShapeRender.new(obj)
|
|
4
8
|
|
|
5
9
|
load_library :vecmath
|
|
6
10
|
|
|
@@ -10,7 +14,7 @@ def setup
|
|
|
10
14
|
size(1024, 768, P3D)
|
|
11
15
|
|
|
12
16
|
texture_mode(NORMAL)
|
|
13
|
-
|
|
17
|
+
no_stroke
|
|
14
18
|
|
|
15
19
|
# Creating offscreen surface for 3D rendering.
|
|
16
20
|
@pg = create_graphics(32, 512, P3D)
|
|
@@ -28,7 +32,7 @@ def draw
|
|
|
28
32
|
background(0)
|
|
29
33
|
|
|
30
34
|
pg.begin_draw
|
|
31
|
-
pg.ellipse(rand
|
|
35
|
+
pg.ellipse(rand(0.0 .. pg.width), rand(0.0 .. pg.height), 4, 4)
|
|
32
36
|
pg.end_draw
|
|
33
37
|
|
|
34
38
|
ambient(250, 250, 250)
|
|
@@ -43,7 +47,7 @@ def draw
|
|
|
43
47
|
end
|
|
44
48
|
|
|
45
49
|
# Code to draw a trefoil knot surface, with normals and texture
|
|
46
|
-
# coordinates.
|
|
50
|
+
# coordinates. Makes of the Vec3D Render interface (uses ShapeRender here).
|
|
47
51
|
# Adapted from the parametric equations example by Philip Rideout:
|
|
48
52
|
# http://iphone-3d-programming.labs.oreilly.com/ch03.html
|
|
49
53
|
|
|
@@ -52,12 +56,13 @@ end
|
|
|
52
56
|
def create_trefoil(s, ny, nx, tex)
|
|
53
57
|
|
|
54
58
|
obj = create_shape()
|
|
59
|
+
|
|
55
60
|
obj.begin_shape(TRIANGLES)
|
|
56
61
|
obj.texture(tex)
|
|
57
|
-
|
|
62
|
+
renderer = ShapeRender.new(obj)
|
|
58
63
|
(0 ... nx).each do |j|
|
|
59
64
|
u0 = j.to_f / nx
|
|
60
|
-
u1 = (j + 1).to_f / nx
|
|
65
|
+
u1 = (j + 1).to_f / nx
|
|
61
66
|
(0 ... ny).each do |i|
|
|
62
67
|
v0 = i.to_f / ny
|
|
63
68
|
v1 = (i + 1).to_f / ny
|
|
@@ -72,23 +77,23 @@ def create_trefoil(s, ny, nx, tex)
|
|
|
72
77
|
n2 = eval_normal(u1, v1)
|
|
73
78
|
|
|
74
79
|
# Triangle p0-p1-p2
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
80
|
+
n0.to_normal(renderer)
|
|
81
|
+
(p0 * s).to_vertex_uv(renderer, u0, v0)
|
|
82
|
+
n1.to_normal(renderer)
|
|
83
|
+
(p1 * s).to_vertex_uv(renderer, u0, v1)
|
|
84
|
+
n2.to_normal(renderer)
|
|
85
|
+
(p2 * s).to_vertex_uv(renderer, u1, v1)
|
|
81
86
|
|
|
82
87
|
p1 = eval_point(u1, v0)
|
|
83
88
|
n1 = eval_normal(u1, v0)
|
|
84
89
|
|
|
85
90
|
# Triangle p0-p2-p1
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
91
|
+
n0.to_normal(renderer)
|
|
92
|
+
(p0 * s).to_vertex_uv(renderer, u0, v0)
|
|
93
|
+
n2.to_normal(renderer)
|
|
94
|
+
(p2 * s).to_vertex_uv(renderer, u1, v1)
|
|
95
|
+
n1.to_normal(renderer)
|
|
96
|
+
(p1 * s).to_vertex_uv(renderer, u1, v0)
|
|
92
97
|
end
|
|
93
98
|
end
|
|
94
99
|
obj.end_shape
|
|
@@ -104,9 +109,7 @@ def eval_normal(u, v)
|
|
|
104
109
|
tangV = eval_point(u, v + 0.01)
|
|
105
110
|
tangU -= p
|
|
106
111
|
tangV -= p
|
|
107
|
-
|
|
108
|
-
normUV = tangV.cross(tangU)
|
|
109
|
-
return normUV.normalize!
|
|
112
|
+
tangV.cross(tangU).normalize! # it is easy to chain Vec3D operations
|
|
110
113
|
end
|
|
111
114
|
|
|
112
115
|
# Evaluates the surface point corresponding to normalized
|
|
@@ -119,24 +122,31 @@ def eval_point(u, v)
|
|
|
119
122
|
s = TAU * u
|
|
120
123
|
t = (TAU * (1 - v)) * 2
|
|
121
124
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
dv.
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
125
|
+
sint = sin(t)
|
|
126
|
+
cost = cos(t)
|
|
127
|
+
sint15 = sin(1.5 * t)
|
|
128
|
+
cost15 = cos(1.5 * t)
|
|
129
|
+
|
|
130
|
+
r = a + b * cost15
|
|
131
|
+
x = r * cost
|
|
132
|
+
y = r * sint
|
|
133
|
+
z = c * sint15
|
|
134
|
+
|
|
135
|
+
dv = Vec3D.new(
|
|
136
|
+
-1.5 * b * sint15 * cost - y,
|
|
137
|
+
-1.5 * b * sint15 * sint + x,
|
|
138
|
+
1.5 * c * cost15)
|
|
139
|
+
|
|
140
|
+
q = dv.normalize # regular normalize creates a new Vec3D for us
|
|
141
|
+
qvn = Vec3D.new(q.y, -q.x, 0).normalize! # chained Vec3D operations
|
|
142
|
+
|
|
143
|
+
ww = q.cross(qvn)
|
|
144
|
+
|
|
145
|
+
coss = cos(s)
|
|
146
|
+
sins = sin(s)
|
|
147
|
+
|
|
148
|
+
Vec3D.new(
|
|
149
|
+
x + d * (qvn.x * coss + ww.x * sins),
|
|
150
|
+
y + d * (qvn.y * coss + ww.y * sins),
|
|
151
|
+
z + d * ww.z * sins)
|
|
142
152
|
end
|
|
@@ -10,10 +10,20 @@ NOISE_MAG = 1.0
|
|
|
10
10
|
# signature-specific alias for overloaded method
|
|
11
11
|
java_alias :background_int, :background, [Java::int]
|
|
12
12
|
|
|
13
|
+
attr_reader :sine, :cosine
|
|
13
14
|
|
|
14
15
|
def setup
|
|
15
|
-
size(1024, 768, P3D);
|
|
16
|
-
|
|
16
|
+
size(1024, 768, P3D);
|
|
17
|
+
@sine = []
|
|
18
|
+
@cosine = []
|
|
19
|
+
wiggling = false
|
|
20
|
+
# Dry up that processing code a tiny bit
|
|
21
|
+
(0 .. TAU).step(TAU / CIRCLE_RES) do |i|
|
|
22
|
+
sine << CIRCLE_RAD * sin(i)
|
|
23
|
+
end
|
|
24
|
+
(0 .. TAU).step(TAU / CIRCLE_RES) do |i|
|
|
25
|
+
cosine << CIRCLE_RAD * cos(i)
|
|
26
|
+
end
|
|
17
27
|
@cube = create_cube
|
|
18
28
|
end
|
|
19
29
|
|
|
@@ -72,9 +82,8 @@ def create_cube
|
|
|
72
82
|
face.end_contour
|
|
73
83
|
face.begin_contour
|
|
74
84
|
CIRCLE_RES.times do |i|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
y = CIRCLE_RAD * cos(angle)
|
|
85
|
+
x = sine[i]
|
|
86
|
+
y = cosine[i]
|
|
78
87
|
z = CUBE_SIZE / 2
|
|
79
88
|
face.vertex(x, y, z)
|
|
80
89
|
end
|
|
@@ -95,9 +104,8 @@ def create_cube
|
|
|
95
104
|
face.end_contour
|
|
96
105
|
face.begin_contour
|
|
97
106
|
CIRCLE_RES.times do |i|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
y = CIRCLE_RAD * cos(angle)
|
|
107
|
+
x = sine[i]
|
|
108
|
+
y = cosine[i]
|
|
101
109
|
z = -CUBE_SIZE / 2
|
|
102
110
|
face.vertex(x, y, z)
|
|
103
111
|
end
|
|
@@ -118,10 +126,9 @@ def create_cube
|
|
|
118
126
|
face.end_contour
|
|
119
127
|
face.begin_contour
|
|
120
128
|
CIRCLE_RES.times do |i|
|
|
121
|
-
angle = TAU * i / CIRCLE_RES
|
|
122
129
|
x = CUBE_SIZE / 2
|
|
123
|
-
y =
|
|
124
|
-
z =
|
|
130
|
+
y = sine[i]
|
|
131
|
+
z = cosine[i]
|
|
125
132
|
face.vertex(x, y, z)
|
|
126
133
|
end
|
|
127
134
|
face.end_contour
|
|
@@ -141,10 +148,9 @@ def create_cube
|
|
|
141
148
|
face.end_contour
|
|
142
149
|
face.begin_contour
|
|
143
150
|
CIRCLE_RES.times do |i|
|
|
144
|
-
angle = TAU * i / CIRCLE_RES
|
|
145
151
|
x = -CUBE_SIZE / 2
|
|
146
|
-
y =
|
|
147
|
-
z =
|
|
152
|
+
y = sine[i]
|
|
153
|
+
z = cosine[i]
|
|
148
154
|
face.vertex(x, y, z)
|
|
149
155
|
end
|
|
150
156
|
face.end_contour
|
|
@@ -164,10 +170,9 @@ def create_cube
|
|
|
164
170
|
face.end_contour
|
|
165
171
|
face.begin_contour
|
|
166
172
|
CIRCLE_RES.times do |i|
|
|
167
|
-
|
|
168
|
-
x = CIRCLE_RAD * sin(angle)
|
|
173
|
+
x = sine[i]
|
|
169
174
|
y = CUBE_SIZE / 2
|
|
170
|
-
z =
|
|
175
|
+
z = cosine[i]
|
|
171
176
|
face.vertex(x, y, z)
|
|
172
177
|
end
|
|
173
178
|
face.end_contour
|
|
@@ -187,10 +192,9 @@ def create_cube
|
|
|
187
192
|
face.end_contour
|
|
188
193
|
face.begin_contour
|
|
189
194
|
CIRCLE_RES.times do |i|
|
|
190
|
-
|
|
191
|
-
x = CIRCLE_RAD * sin(angle)
|
|
195
|
+
x = sine[i]
|
|
192
196
|
y = -CUBE_SIZE / 2
|
|
193
|
-
z =
|
|
197
|
+
z = cosine[i]
|
|
194
198
|
face.vertex(x, y, z)
|
|
195
199
|
end
|
|
196
200
|
face.end_contour
|
|
@@ -209,9 +213,8 @@ def restore_cube
|
|
|
209
213
|
face.set_vertex(2, CUBE_SIZE / 2, CUBE_SIZE / 2, CUBE_SIZE / 2)
|
|
210
214
|
face.set_vertex(3, -CUBE_SIZE / 2, CUBE_SIZE / 2, CUBE_SIZE / 2)
|
|
211
215
|
CIRCLE_RES.times do |i|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
y = CIRCLE_RAD * cos(angle)
|
|
216
|
+
x = sine[i]
|
|
217
|
+
y = cosine[i]
|
|
215
218
|
z = CUBE_SIZE / 2
|
|
216
219
|
face.set_vertex(4 + i, x, y, z)
|
|
217
220
|
end
|
|
@@ -223,9 +226,8 @@ def restore_cube
|
|
|
223
226
|
face.set_vertex(2, -CUBE_SIZE / 2, CUBE_SIZE / 2, -CUBE_SIZE / 2)
|
|
224
227
|
face.set_vertex(3, CUBE_SIZE / 2, CUBE_SIZE / 2, -CUBE_SIZE / 2)
|
|
225
228
|
CIRCLE_RES.times do |i|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
y = CIRCLE_RAD * cos(angle)
|
|
229
|
+
x = sine[i]
|
|
230
|
+
y = cosine[i]
|
|
229
231
|
z = -CUBE_SIZE / 2
|
|
230
232
|
face.set_vertex(4 + i, x, y, z)
|
|
231
233
|
end
|
|
@@ -237,10 +239,9 @@ def restore_cube
|
|
|
237
239
|
face.set_vertex(2, CUBE_SIZE / 2, CUBE_SIZE / 2, -CUBE_SIZE / 2)
|
|
238
240
|
face.set_vertex(3, CUBE_SIZE / 2, CUBE_SIZE / 2, CUBE_SIZE / 2)
|
|
239
241
|
CIRCLE_RES.times do |i|
|
|
240
|
-
angle = TAU * i / CIRCLE_RES
|
|
241
242
|
x = CUBE_SIZE / 2
|
|
242
|
-
y =
|
|
243
|
-
z =
|
|
243
|
+
y = sine[i]
|
|
244
|
+
z = cosine[i]
|
|
244
245
|
face.set_vertex(4 + i, x, y, z)
|
|
245
246
|
end
|
|
246
247
|
|
|
@@ -251,10 +252,9 @@ def restore_cube
|
|
|
251
252
|
face.set_vertex(2, -CUBE_SIZE / 2, CUBE_SIZE / 2, CUBE_SIZE / 2)
|
|
252
253
|
face.set_vertex(3, -CUBE_SIZE / 2, CUBE_SIZE / 2, -CUBE_SIZE / 2)
|
|
253
254
|
CIRCLE_RES.times do |i|
|
|
254
|
-
angle = TAU * i / CIRCLE_RES
|
|
255
255
|
x = -CUBE_SIZE / 2
|
|
256
|
-
y =
|
|
257
|
-
z =
|
|
256
|
+
y = sine[i]
|
|
257
|
+
z = cosine[i]
|
|
258
258
|
face.set_vertex(4 + i, x, y, z)
|
|
259
259
|
end
|
|
260
260
|
|
|
@@ -265,10 +265,9 @@ def restore_cube
|
|
|
265
265
|
face.set_vertex(2, CUBE_SIZE / 2, CUBE_SIZE / 2, -CUBE_SIZE / 2)
|
|
266
266
|
face.set_vertex(3, -CUBE_SIZE / 2, CUBE_SIZE / 2, -CUBE_SIZE / 2)
|
|
267
267
|
CIRCLE_RES.times do |i|
|
|
268
|
-
|
|
269
|
-
x = CIRCLE_RAD * sin(angle)
|
|
268
|
+
x = sine[i]
|
|
270
269
|
y = CUBE_SIZE / 2
|
|
271
|
-
z =
|
|
270
|
+
z = cosine[i]
|
|
272
271
|
face.set_vertex(4 + i, x, y, z)
|
|
273
272
|
end
|
|
274
273
|
|
|
@@ -279,10 +278,9 @@ def restore_cube
|
|
|
279
278
|
face.set_vertex(2, -CUBE_SIZE / 2, -CUBE_SIZE / 2, -CUBE_SIZE / 2)
|
|
280
279
|
face.set_vertex(3, CUBE_SIZE / 2, -CUBE_SIZE / 2, -CUBE_SIZE / 2)
|
|
281
280
|
CIRCLE_RES.times do |i|
|
|
282
|
-
|
|
283
|
-
x = CIRCLE_RAD * sin(angle)
|
|
281
|
+
x = sine[i]
|
|
284
282
|
y = -CUBE_SIZE / 2
|
|
285
|
-
z =
|
|
283
|
+
z = cosine[i]
|
|
286
284
|
face.set_vertex(4 + i, x, y, z)
|
|
287
285
|
end
|
|
288
286
|
end
|