ruby-processing 2.4.4 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rpextras.jar +0 -0
- data/lib/ruby-processing.rb +8 -6
- data/lib/ruby-processing/app.rb +54 -67
- data/lib/ruby-processing/config.rb +7 -7
- data/lib/ruby-processing/exporters/application_exporter.rb +37 -38
- data/lib/ruby-processing/exporters/base_exporter.rb +34 -37
- data/lib/ruby-processing/exporters/creator.rb +27 -25
- data/lib/ruby-processing/helper_methods.rb +18 -22
- data/lib/ruby-processing/helpers/numeric.rb +5 -6
- data/lib/ruby-processing/helpers/string.rb +11 -20
- data/lib/ruby-processing/library_loader.rb +33 -35
- data/lib/ruby-processing/runner.rb +118 -65
- data/lib/ruby-processing/runners/base.rb +21 -26
- data/lib/ruby-processing/runners/live.rb +3 -4
- data/lib/ruby-processing/runners/run.rb +1 -3
- data/lib/ruby-processing/runners/watch.rb +8 -8
- data/lib/ruby-processing/version.rb +1 -1
- data/lib/templates/application/lib/args.txt.erb +1 -1
- data/lib/templates/application/run.erb +3 -3
- data/library/control_panel/control_panel.rb +29 -29
- data/library/fastmath/fastmath.rb +3 -0
- data/library/file_chooser/file_chooser.rb +11 -13
- data/library/vecmath/vecmath.rb +6 -35
- data/samples/Rakefile +3 -1
- data/samples/configRP5/configRP5.pde +150 -0
- data/samples/contributed/Rakefile +6 -6
- data/samples/contributed/animator.rb +6 -6
- data/samples/contributed/bezier_playground.rb +29 -68
- data/samples/contributed/circle_collision.rb +6 -13
- data/samples/contributed/elegant_ball.rb +14 -17
- data/samples/contributed/empathy.rb +8 -5
- data/samples/contributed/fibonacci_sphere.rb +10 -49
- data/samples/contributed/full_screen.rb +1 -1
- data/samples/contributed/grapher.rb +10 -9
- data/samples/contributed/gravity.rb +11 -16
- data/samples/contributed/jwishy.rb +18 -20
- data/samples/contributed/quadraticvertex.rb +26 -26
- data/samples/external_library/java_processing/custom/landscape.rb +6 -4
- data/samples/external_library/java_processing/hemesh/twin_iso.rb +69 -71
- data/samples/external_library/java_processing/pbox2d/bumpy_surface_noise.rb +57 -0
- data/samples/external_library/java_processing/pbox2d/contact_test.rb +23 -0
- data/samples/external_library/java_processing/pbox2d/data/java_args.txt +2 -0
- data/samples/external_library/java_processing/pbox2d/library/custom_shape/custom_shape.rb +158 -0
- data/samples/external_library/java_processing/pbox2d/library/particle_system/particle_system.rb +212 -0
- data/samples/external_library/java_processing/pbox2d/library/surface/surface.rb +154 -0
- data/samples/external_library/java_processing/pbox2d/liquidy.rb +58 -0
- data/samples/external_library/java_processing/pbox2d/polygons.rb +58 -0
- data/samples/external_library/java_processing/toxiclibs/library/vbo/vbo.rb +52 -0
- data/samples/external_library/java_processing/toxiclibs/model_align.rb +9 -16
- data/samples/processing_app/basics/color/color_wheel.rb +1 -1
- data/samples/processing_app/basics/form/regular_polygon.rb +2 -2
- data/samples/processing_app/basics/form/rgb_cube.rb +2 -2
- data/samples/processing_app/basics/form/shape_primitives.rb +1 -1
- data/samples/processing_app/basics/form/star.rb +2 -2
- data/samples/processing_app/basics/input/clock.rb +21 -16
- data/samples/processing_app/basics/input/storing_input.rb +6 -6
- data/samples/processing_app/basics/math/additive_wave.rb +1 -1
- data/samples/processing_app/basics/math/sine.rb +2 -2
- data/samples/processing_app/basics/math/sine_cosine.rb +1 -1
- data/samples/processing_app/basics/math/sine_wave.rb +1 -1
- data/samples/processing_app/basics/objects/inheritance.rb +2 -0
- data/samples/processing_app/basics/objects/inheritance_two.rb +88 -0
- data/samples/processing_app/basics/objects/module.rb +89 -0
- data/samples/processing_app/{library/vecmath/drawolver.rb → basics/objects/module_two.rb} +1 -1
- data/samples/processing_app/basics/objects/multiple_constructors.rb +5 -0
- data/samples/processing_app/basics/objects/struct.rb +38 -0
- data/samples/processing_app/basics/structure/recursion2.rb +1 -1
- data/samples/processing_app/basics/transform/birds.rb +7 -10
- data/samples/processing_app/basics/transform/library/bird/bird.rb +3 -3
- data/samples/processing_app/basics/transform/rotate.rb +1 -1
- data/samples/processing_app/basics/transform/rotate1.rb +1 -1
- data/samples/processing_app/basics/transform/rotate_x_y.rb +1 -1
- data/samples/processing_app/demos/graphics/bezier_patch.rb +1 -38
- data/samples/processing_app/demos/graphics/trefoil.rb +50 -40
- data/samples/processing_app/demos/graphics/wiggling.rb +36 -38
- data/samples/processing_app/demos/performance/cubic_grid_retained.rb +14 -14
- data/samples/processing_app/demos/performance/esfera.rb +27 -39
- data/samples/processing_app/demos/performance/text_rendering.rb +1 -1
- data/samples/processing_app/library/fastmath/clock.rb +44 -0
- data/samples/processing_app/library/pdf/complex_3D.rb +26 -24
- data/samples/processing_app/library/vecmath/{Rakefile → arcball/Rakefile} +6 -6
- data/samples/processing_app/library/vecmath/arcball/arcball_box.rb +23 -0
- data/samples/processing_app/library/vecmath/arcball/arcball_radius.rb +23 -0
- data/samples/processing_app/library/vecmath/arcball/arcball_shape.rb +29 -0
- data/samples/processing_app/library/vecmath/{README.txt → vec2d/README.txt} +0 -0
- data/samples/processing_app/library/vecmath/vec2d/Rakefile +30 -0
- data/samples/processing_app/library/vecmath/{acceleration_with_vectors.rb → vec2d/acceleration_with_vectors.rb} +4 -5
- data/samples/processing_app/library/vecmath/{bouncing_ball.rb → vec2d/bouncing_ball.rb} +9 -15
- data/samples/processing_app/library/vecmath/{circle_collision.rb → vec2d/circle_collision.rb} +46 -51
- data/samples/processing_app/library/vecmath/{data → vec2d/data}/java_args.txt +0 -0
- data/samples/processing_app/library/vecmath/{data → vec2d/data}/sprite.png +0 -0
- data/samples/processing_app/library/vecmath/{data → vec2d/data}/texture.png +0 -0
- data/samples/processing_app/library/vecmath/{flocking.rb → vec2d/flocking.rb} +3 -6
- data/samples/processing_app/library/vecmath/{library → vec2d/library}/flock/flock.rb +47 -67
- data/samples/processing_app/library/vecmath/{library → vec2d/library}/particle/particle_system.rb +5 -5
- data/samples/processing_app/library/vecmath/vec2d/library/tile/tile.rb +85 -0
- data/samples/processing_app/library/vecmath/{morph.rb → vec2d/morph.rb} +17 -16
- data/samples/processing_app/library/vecmath/{multiple_particle_systems.rb → vec2d/multiple_particle_systems.rb} +11 -28
- data/samples/processing_app/library/vecmath/{particle_system_pshape.rb → vec2d/particle_system_pshape.rb} +4 -6
- data/samples/processing_app/library/vecmath/vec2d/penrose.rb +71 -0
- data/samples/processing_app/library/vecmath/{reflection1.rb → vec2d/reflection1.rb} +6 -6
- data/samples/processing_app/library/vecmath/{seeking_neural.rb → vec2d/seeking_neural.rb} +12 -16
- data/samples/processing_app/library/vecmath/{simple_particle_system.rb → vec2d/simple_particle_system.rb} +8 -12
- data/samples/processing_app/library/vecmath/{smoke_particle_system.rb → vec2d/smoke_particle_system.rb} +8 -13
- data/samples/processing_app/library/vecmath/{vector_math.rb → vec2d/vector_math.rb} +0 -0
- data/samples/processing_app/library/vecmath/{library/wiggler/wiggler.rb → vec2d/wiggle_pshape.rb} +28 -4
- data/samples/processing_app/library/vecmath/vec3d/Rakefile +30 -0
- data/samples/processing_app/library/vecmath/vec3d/drawolver.rb +86 -0
- data/samples/processing_app/library/vecmath/vec3d/frame_of_reference.rb +103 -0
- data/samples/processing_app/library/vecmath/{hilbert_fractal.rb → vec3d/hilbert_fractal.rb} +5 -33
- data/samples/processing_app/library/vecmath/vec3d/library/geometry/geometry.rb +3 -0
- data/samples/processing_app/library/vecmath/vec3d/library/geometry/lib/cylinder.rb +44 -0
- data/samples/processing_app/library/vecmath/vec3d/library/geometry/lib/mat4.rb +28 -0
- data/samples/processing_app/library/vecmath/vec3d/library/geometry/lib/plane.rb +60 -0
- data/samples/processing_app/library/vecmath/{library → vec3d/library}/hilbert/hilbert.rb +14 -17
- data/samples/processing_app/library/vecmath/{retained_menger.rb → vec3d/retained_menger.rb} +20 -55
- data/samples/processing_app/topics/advanced_data/Rakefile +6 -6
- data/samples/processing_app/topics/advanced_data/counting_words.rb +7 -7
- data/samples/processing_app/topics/advanced_data/data/data.xml +0 -15
- data/samples/processing_app/topics/advanced_data/data/struct_data.yml +5 -0
- data/samples/processing_app/topics/advanced_data/library/bubble/bubble.rb +8 -8
- data/samples/processing_app/topics/advanced_data/load_save_XML.rb +41 -42
- data/samples/processing_app/topics/advanced_data/load_save_json.rb +11 -11
- data/samples/processing_app/topics/advanced_data/load_save_struct_yaml.rb +22 -23
- data/samples/processing_app/topics/advanced_data/load_save_table.rb +12 -12
- data/samples/processing_app/topics/advanced_data/load_save_yaml.rb +10 -12
- data/samples/processing_app/topics/advanced_data/regex.rb +5 -6
- data/samples/processing_app/topics/advanced_data/threads.rb +27 -27
- data/samples/processing_app/topics/advanced_data/threads_two.rb +3 -2
- data/samples/processing_app/topics/advanced_data/word_frequency.rb +18 -16
- data/samples/processing_app/topics/advanced_data/yahoo_weather.rb +6 -5
- data/samples/processing_app/topics/animation/animated_sprite.rb +9 -7
- data/samples/processing_app/topics/animation/sequential.rb +19 -19
- data/samples/processing_app/topics/cellular_automata/library/ca/ca.rb +1 -1
- data/samples/processing_app/topics/cellular_automata/wolfram.rb +1 -1
- data/samples/processing_app/topics/create_shapes/begin_end_contour.rb +1 -1
- data/samples/processing_app/topics/create_shapes/library/wiggler/wiggler.rb +4 -4
- data/samples/processing_app/topics/create_shapes/particle_system_pshape.rb +2 -2
- data/samples/processing_app/topics/create_shapes/path_pshape.rb +1 -1
- data/samples/processing_app/topics/create_shapes/polygon_pshape_oo3.rb +1 -1
- data/samples/processing_app/topics/create_shapes/polygon_shape.rb +3 -3
- data/samples/processing_app/topics/file_io/load_file1.rb +1 -1
- data/samples/processing_app/topics/file_io/save_frames.rb +5 -5
- data/samples/processing_app/topics/file_io/save_one_image.rb +2 -2
- data/samples/processing_app/topics/file_io/tile_images.rb +1 -1
- data/samples/processing_app/topics/gui/scrollbar.rb +3 -3
- data/samples/processing_app/topics/image_processing/blending.rb +13 -13
- data/samples/processing_app/topics/image_processing/blur.rb +1 -1
- data/samples/processing_app/topics/image_processing/brightness.rb +1 -1
- data/samples/processing_app/topics/image_processing/convolution.rb +1 -1
- data/samples/processing_app/topics/image_processing/edge_detection.rb +4 -4
- data/samples/processing_app/topics/image_processing/explode.rb +1 -1
- data/samples/processing_app/topics/image_processing/extrusion.rb +1 -1
- data/samples/processing_app/topics/image_processing/histogram.rb +1 -1
- data/samples/processing_app/topics/image_processing/linear_image.rb +1 -1
- data/samples/processing_app/topics/image_processing/pixel_array.rb +1 -1
- data/samples/processing_app/topics/image_processing/zoom.rb +2 -2
- data/samples/processing_app/topics/lsystems/Rakefile +6 -6
- data/samples/processing_app/topics/lsystems/chequer.rb +4 -10
- data/samples/processing_app/topics/lsystems/csplant.rb +25 -25
- data/samples/processing_app/topics/lsystems/cstest.rb +9 -4
- data/samples/processing_app/topics/lsystems/david_tour.rb +14 -16
- data/samples/processing_app/topics/lsystems/koch.rb +8 -18
- data/samples/processing_app/topics/lsystems/library/cs_grammar/cs_grammar.rb +18 -24
- data/samples/processing_app/topics/lsystems/library/grammar/grammar.rb +7 -9
- data/samples/processing_app/topics/lsystems/library/koch/koch_fractal.rb +75 -94
- data/samples/processing_app/topics/lsystems/library/stochastic_grammar/stochastic_grammar.rb +11 -13
- data/samples/processing_app/topics/lsystems/mpeano.rb +29 -32
- data/samples/processing_app/topics/lsystems/peano.rb +19 -21
- data/samples/processing_app/topics/lsystems/penrose.rb +31 -37
- data/samples/processing_app/topics/lsystems/penrose_snowflake.rb +10 -15
- data/samples/processing_app/topics/lsystems/pentagonal.rb +20 -23
- data/samples/processing_app/topics/lsystems/snake_kolam.rb +13 -13
- data/samples/processing_app/topics/lsystems/stochastic_test.rb +25 -28
- data/samples/processing_app/topics/lsystems/three_d_tree.rb +25 -24
- data/samples/processing_app/topics/motion/bouncy_bubbles.rb +17 -17
- data/samples/processing_app/topics/motion/cubes_in_cube.rb +1 -3
- data/samples/processing_app/topics/motion/library/cube/cube.rb +2 -2
- data/samples/processing_app/topics/motion/reflection2.rb +1 -1
- data/samples/processing_app/topics/shaders/blur_filter.rb +3 -3
- data/samples/processing_app/topics/shaders/bw_shader.rb +3 -3
- data/samples/processing_app/topics/shaders/conway.rb +5 -5
- data/samples/processing_app/topics/shaders/deform.rb +5 -5
- data/samples/processing_app/topics/shaders/edge_detect.rb +3 -5
- data/samples/processing_app/topics/shaders/glossy_fish_eye.rb +15 -21
- data/samples/processing_app/topics/shaders/glsl_heightmap_noise.rb +21 -19
- data/samples/processing_app/topics/shaders/image_mask.rb +6 -6
- data/samples/processing_app/topics/shaders/landscape.rb +4 -4
- data/samples/processing_app/topics/shaders/monjori.rb +15 -15
- data/samples/processing_app/topics/shaders/nebula.rb +3 -3
- data/samples/processing_app/topics/shaders/sep_blur.rb +15 -15
- data/samples/processing_app/topics/shaders/toon_shading.rb +2 -2
- data/samples/processing_app/topics/simulate/chain.rb +16 -14
- data/samples/processing_app/topics/simulate/smoke_particle_system.rb +3 -3
- data/samples/processing_app/topics/vectors/acceleration_with_vectors.rb +3 -2
- data/samples/processing_app/topics/vectors/bouncing_ball.rb +1 -0
- data/samples/processing_app/topics/vectors/vector_math.rb +2 -1
- data/vendors/Rakefile +15 -3
- metadata +99 -86
- data/.gitignore +0 -13
- data/.travis.yml +0 -6
- data/.yardopts +0 -5
- data/CHANGELOG +0 -316
- data/CONTRIBUTING.md +0 -35
- data/Gemfile +0 -6
- data/LICENSE.md +0 -39
- data/README.md +0 -119
- data/Rakefile +0 -37
- data/bin/install_jruby_complete +0 -13
- data/lib/ruby-processing/exporters/exporters.rb +0 -7
- data/library/vecmath/lib/arcball.rb +0 -64
- data/library/vecmath/lib/quaternion.rb +0 -62
- data/library/vecmath/lib/vec.rb +0 -232
- data/ruby-processing.gemspec +0 -54
- data/samples/processing_app/library/pdf/.gitignore +0 -1
- data/samples/processing_app/library/vecmath/retained_test.rb +0 -65
- data/samples/processing_app/library/vecmath/retained_test2.rb +0 -65
- data/samples/processing_app/library/vecmath/wiggle_pshape.rb +0 -22
- data/test/README.md +0 -6
- data/test/basic.rb +0 -14
- data/test/draw_ex.rb +0 -12
- data/test/graphics.rb +0 -7
- data/test/p2d.rb +0 -14
- data/test/p3d.rb +0 -14
- data/test/rp5_test.rb +0 -86
- data/test/setup_ex.rb +0 -12
@@ -2,8 +2,8 @@
|
|
2
2
|
# Part of a series of articles on Processing 2.
|
3
3
|
# Blog post here:
|
4
4
|
# http://vormplus.be/blog/article/drawing-shapes-with-quadratic-vertices
|
5
|
-
# translated for ruby-processing by Martin Prout
|
6
|
-
# Note how to specify fill and background using hexadecimal string for color,
|
5
|
+
# translated for ruby-processing by Martin Prout
|
6
|
+
# Note how to specify fill and background using hexadecimal string for color,
|
7
7
|
# this is different from vanilla processing
|
8
8
|
#
|
9
9
|
|
@@ -16,14 +16,14 @@ def setup
|
|
16
16
|
@hide = false
|
17
17
|
control_panel do |c|
|
18
18
|
c.title = "controller"
|
19
|
-
c.menu(:detail,
|
19
|
+
c.menu(:detail, %w(4 5 6 7 8 9 10), '7')
|
20
20
|
c.button :toggle_debug
|
21
21
|
c.button :save_image
|
22
22
|
@panel = c
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
@debug = false
|
26
|
-
@save_one = false
|
26
|
+
@save_one = false
|
27
27
|
smooth 8
|
28
28
|
end
|
29
29
|
|
@@ -33,45 +33,45 @@ def draw
|
|
33
33
|
@hide = true
|
34
34
|
end
|
35
35
|
background color('#BDF018')
|
36
|
-
translate width / 2, height / 2
|
37
|
-
@step_angle =
|
36
|
+
translate width / 2, height / 2
|
37
|
+
@step_angle = TAU / (detail.to_i - 1)
|
38
38
|
fill color('#ffffff')
|
39
39
|
no_stroke
|
40
40
|
@cr = map(mouse_x, 0, width, 20, 200)
|
41
41
|
begin_shape
|
42
|
-
detail.to_i.times do |i|
|
43
|
-
if (i == 0)
|
44
|
-
vertex cos_x(i), sin_y(i)
|
45
|
-
else
|
42
|
+
detail.to_i.times do |i|
|
43
|
+
if (i == 0)
|
44
|
+
vertex cos_x(i), sin_y(i)
|
45
|
+
else
|
46
46
|
quadratic_vertex cos_cx(i), sin_cy(i), cos_x(i), sin_y(i)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end_shape(CLOSE)
|
50
|
-
|
51
|
-
if (debug)
|
50
|
+
|
51
|
+
if (debug)
|
52
52
|
# draw lines between points
|
53
53
|
stroke_weight(1)
|
54
54
|
no_fill
|
55
55
|
stroke(0)
|
56
|
-
|
56
|
+
|
57
57
|
begin_shape
|
58
|
-
detail.to_i.times do |i|
|
59
|
-
vertex cos_cx(i), sin_cy(i) unless i == 0
|
60
|
-
vertex cos_x(i), sin_y(i)
|
58
|
+
detail.to_i.times do |i|
|
59
|
+
vertex cos_cx(i), sin_cy(i) unless i == 0
|
60
|
+
vertex cos_x(i), sin_y(i)
|
61
61
|
end
|
62
62
|
end_shape CLOSE
|
63
|
-
|
63
|
+
|
64
64
|
# draw points
|
65
|
-
stroke_weight 8
|
66
|
-
detail.to_i.times do |i|
|
67
|
-
stroke 0
|
68
|
-
point cos_x(i), sin_y(i)
|
69
|
-
stroke 255, 0, 0
|
70
|
-
point cos_cx(i), sin_cy(i)
|
65
|
+
stroke_weight 8
|
66
|
+
detail.to_i.times do |i|
|
67
|
+
stroke 0
|
68
|
+
point cos_x(i), sin_y(i)
|
69
|
+
stroke 255, 0, 0
|
70
|
+
point cos_cx(i), sin_cy(i)
|
71
71
|
end
|
72
72
|
end
|
73
|
-
|
74
|
-
if
|
73
|
+
|
74
|
+
if save_one
|
75
75
|
save_frame("images/quadraticvertex-#####.png")
|
76
76
|
@save_one = false
|
77
77
|
end
|
@@ -23,7 +23,9 @@ class Landscape
|
|
23
23
|
def calculate(nn)
|
24
24
|
val = ->(curr, nn, x, y){curr * 0.95 + 0.05 * (nn.feed_forward([x, y]) * 280.0 - 140.0)}
|
25
25
|
@z = (0 ... cols).map{|i|
|
26
|
-
(0 ... rows).map{|j|
|
26
|
+
(0 ... rows).map{|j|
|
27
|
+
val.call(z[i][j], nn, i * 1.0/ cols, j * 1.0/cols)
|
28
|
+
}
|
27
29
|
}
|
28
30
|
end
|
29
31
|
|
@@ -49,10 +51,10 @@ class Landscape
|
|
49
51
|
vertex(scl, scl, z[x+1][y+1])
|
50
52
|
fill(z[x][y+1]+127, 220)
|
51
53
|
vertex(0, scl, z[x][y+1])
|
52
|
-
|
53
|
-
|
54
|
+
end_shape
|
55
|
+
pop_matrix
|
56
|
+
end
|
54
57
|
end
|
55
58
|
end
|
56
59
|
end
|
57
|
-
end
|
58
60
|
|
@@ -1,71 +1,69 @@
|
|
1
|
-
load_libraries :hemesh, :vbo
|
2
|
-
|
3
|
-
include MS # module MS imports necessary java classes and contains ruby MeshToVBO class
|
4
|
-
|
5
|
-
RES = 20
|
6
|
-
|
7
|
-
attr_reader :mesh_ret, :inv_mesh_ret, :render
|
8
|
-
|
9
|
-
def setup
|
10
|
-
size(800, 800, P3D)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
creator
|
27
|
-
creator.
|
28
|
-
|
29
|
-
|
30
|
-
#
|
31
|
-
#
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
creator.
|
37
|
-
creator.
|
38
|
-
|
39
|
-
#
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
inv_mesh.
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
@
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
spot_light(30, 30, 30, 0, 40, 200, 0, -0.5, 0.5, PI / 2, 2)
|
71
|
-
end
|
1
|
+
load_libraries :hemesh, :vbo, :vecmath
|
2
|
+
|
3
|
+
include MS # module MS imports necessary java classes and contains ruby MeshToVBO class
|
4
|
+
|
5
|
+
RES = 20
|
6
|
+
|
7
|
+
attr_reader :mesh_ret, :inv_mesh_ret, :render
|
8
|
+
|
9
|
+
def setup
|
10
|
+
size(800, 800, P3D)
|
11
|
+
ArcBall.init(self)
|
12
|
+
smooth(8)
|
13
|
+
values = [] # build a multi-dimensional array in ruby
|
14
|
+
(0 .. RES).each do |i| # the inclusive range is intentional here
|
15
|
+
valu = []
|
16
|
+
(0 .. RES).each do |j|
|
17
|
+
val = []
|
18
|
+
(0 .. RES).each do |k|
|
19
|
+
val << 2.1 * noise(0.35 * i, 0.35 * j, 0.35 * k)
|
20
|
+
end
|
21
|
+
valu << val
|
22
|
+
end
|
23
|
+
values << valu
|
24
|
+
end
|
25
|
+
|
26
|
+
creator = HEC_IsoSurface.new
|
27
|
+
creator.set_resolution(RES,RES, RES) # number of cells in x,y,z direction
|
28
|
+
creator.set_size(400.0/RES, 400.0/RES, 400.0/RES) # cell size
|
29
|
+
|
30
|
+
# JRuby requires a bit of help to determine correct 'java args', particulary with
|
31
|
+
# overloaded arrays args as seen below. Note we are saying we have an 'array' of
|
32
|
+
# 'float array' here, where the values can also be double[][][].
|
33
|
+
java_values = values.to_java(Java::float[][]) # pre-coerce values to java
|
34
|
+
creator.set_values(java_values) # the grid points
|
35
|
+
|
36
|
+
creator.set_isolevel(1) # isolevel to mesh
|
37
|
+
creator.set_invert(false) # invert mesh
|
38
|
+
creator.set_boundary(100) # value of isoFunction outside grid
|
39
|
+
# use creator.clear_boundary to set boundary values to "no value".
|
40
|
+
# A boundary value of "no value" results in an open mesh
|
41
|
+
|
42
|
+
mesh = HE_Mesh.new(creator)
|
43
|
+
# mesh.modify(HEM_Smooth.new.set_iterations(10).setAutoRescale(true))
|
44
|
+
creator.set_invert(true)
|
45
|
+
|
46
|
+
inv_mesh = HE_Mesh.new(creator)
|
47
|
+
inv_mesh.modify(HEM_Smooth.new.set_iterations(10).set_auto_rescale(true))
|
48
|
+
@render = MeshToVBO.new(self)
|
49
|
+
no_stroke
|
50
|
+
# no color args produces a default light grey fill
|
51
|
+
@mesh_ret = render.meshToVBO(mesh, color(200, 0, 0))
|
52
|
+
@inv_mesh_ret = render.meshToVBO(inv_mesh, color(0, 0, 200))
|
53
|
+
end
|
54
|
+
|
55
|
+
def draw
|
56
|
+
background(120)
|
57
|
+
lights
|
58
|
+
define_lights
|
59
|
+
shape(inv_mesh_ret)
|
60
|
+
shape(mesh_ret)
|
61
|
+
end
|
62
|
+
|
63
|
+
def define_lights
|
64
|
+
ambient(80, 80, 80)
|
65
|
+
ambient_light(80, 80, 80)
|
66
|
+
point_light(30, 30, 30, 0, 0, 1)
|
67
|
+
directional_light(40, 40, 50, 0, 0, 1)
|
68
|
+
spot_light(30, 30, 30, 0, 40, 200, 0, -0.5, 0.5, PI / 2, 2)
|
69
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# The Nature of Code
|
2
|
+
# <http:#www.shiffman.net/teaching/nature>
|
3
|
+
# Spring 2010
|
4
|
+
# PBox2D example
|
5
|
+
|
6
|
+
# An uneven surface
|
7
|
+
|
8
|
+
load_library :jbox2d
|
9
|
+
load_library :surface
|
10
|
+
|
11
|
+
include SB
|
12
|
+
|
13
|
+
attr_reader :surface, :box2d, :particles
|
14
|
+
|
15
|
+
def setup
|
16
|
+
size(500,300)
|
17
|
+
smooth
|
18
|
+
|
19
|
+
# Initialize box2d physics and create the world
|
20
|
+
@box2d = Processing::Box2d::Box2d.new(self)
|
21
|
+
box2d.create_world
|
22
|
+
# We are setting a custom gravity
|
23
|
+
box2d.set_gravity(0, -20)
|
24
|
+
|
25
|
+
# Create the empty list
|
26
|
+
@particles = []
|
27
|
+
# Create the surface
|
28
|
+
@surface = Surface.new(box2d)
|
29
|
+
end
|
30
|
+
|
31
|
+
def draw
|
32
|
+
# If the mouse is pressed, we make new particles
|
33
|
+
|
34
|
+
|
35
|
+
# We must always step through time!
|
36
|
+
box2d.step
|
37
|
+
|
38
|
+
background(138, 66, 54)
|
39
|
+
# Draw the surface
|
40
|
+
surface.display
|
41
|
+
# NB question mark is reqd to call mouse_pressed value, else method gets called.
|
42
|
+
particles << Particle.new(box2d, mouse_x, mouse_y, rand(2.0 .. 6)) if mouse_pressed?
|
43
|
+
# Draw all particles
|
44
|
+
particles.each do |p|
|
45
|
+
p.display
|
46
|
+
end
|
47
|
+
# Particles that leave the screen, we delete them
|
48
|
+
# (note they have to be deleted from both the box2d world and our list
|
49
|
+
particles.each_with_index do |p, i|
|
50
|
+
if (p.done)
|
51
|
+
particles.delete_at(i)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
# Just drawing the framerate to see how many particles it can handle
|
55
|
+
fill(0)
|
56
|
+
text("framerate: #{frame_rate.to_i}", 12, 16)
|
57
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
load_library 'jbox2d'
|
2
|
+
require 'jruby/core_ext'
|
3
|
+
class JContactListener
|
4
|
+
include org.jbox2d.callbacks.ContactListener
|
5
|
+
|
6
|
+
def initialize()
|
7
|
+
end
|
8
|
+
java_signature "void beginContact(org.jbox2d.dynamics.contacts.Contact c)"
|
9
|
+
def begin_contact(c)
|
10
|
+
end
|
11
|
+
java_signature "void endContact(org.jbox2d.dynamics.contacts.Contact c)"
|
12
|
+
def end_contact(c)
|
13
|
+
end
|
14
|
+
java_signature "void beginContact(org.jbox2d.dynamics.contacts.Contact,org.jbox2d.callbacks.ContactImpulse )"
|
15
|
+
def pre_solve(c, ci)
|
16
|
+
end
|
17
|
+
java_signature "void beginContact(org.jbox2d.dynamics.contacts.Contact,org.jbox2d.callbacks.ContactImpulse )"
|
18
|
+
def post_solve(c, ci)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
|
@@ -0,0 +1,158 @@
|
|
1
|
+
module B2D
|
2
|
+
include_package 'pbox2d'
|
3
|
+
include_package 'org.jbox2d.collision.shapes'
|
4
|
+
include_package 'org.jbox2d.common'
|
5
|
+
include_package 'org.jbox2d.dynamics'
|
6
|
+
java_import 'pbox2d.PBox2D'
|
7
|
+
|
8
|
+
|
9
|
+
# The Nature of Code
|
10
|
+
# <http://www.shiffman.net/teaching/nature>
|
11
|
+
# Spring 2011
|
12
|
+
# PBox2D example
|
13
|
+
# A rectangular box
|
14
|
+
|
15
|
+
class CustomShape
|
16
|
+
|
17
|
+
# We need to keep track of a Body and a width and height
|
18
|
+
attr_reader :body, :box2d
|
19
|
+
|
20
|
+
# Constructor
|
21
|
+
def initialize(b2d, x, y)
|
22
|
+
# Add the box to the box2d world
|
23
|
+
@box2d = b2d
|
24
|
+
make_body(B2D::Vec2.new(x, y))
|
25
|
+
end
|
26
|
+
|
27
|
+
# This function removes the particle from the box2d world
|
28
|
+
def kill_body!
|
29
|
+
box2d.destroy_body(body)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Is the particle ready for deletion?
|
33
|
+
def done
|
34
|
+
# Let's find the screen position of the particle
|
35
|
+
pos = box2d.get_body_pixel_coord(body)
|
36
|
+
# Is it off the bottom of the screen?
|
37
|
+
if (pos.y > $app.height)
|
38
|
+
kill_body!
|
39
|
+
return true
|
40
|
+
end
|
41
|
+
return false
|
42
|
+
end
|
43
|
+
|
44
|
+
# Drawing the box
|
45
|
+
def display
|
46
|
+
# We look at each body and get its screen position
|
47
|
+
pos = box2d.get_body_pixel_coord(body)
|
48
|
+
# Get its angle of rotation
|
49
|
+
a = body.get_angle
|
50
|
+
|
51
|
+
f = body.get_fixture_list
|
52
|
+
ps = f.get_shape
|
53
|
+
|
54
|
+
|
55
|
+
rect_mode(CENTER)
|
56
|
+
push_matrix
|
57
|
+
translate(pos.x, pos.y)
|
58
|
+
rotate(-a)
|
59
|
+
fill(175)
|
60
|
+
stroke(0)
|
61
|
+
begin_shape
|
62
|
+
# For every vertex, convert to pixel vector
|
63
|
+
ps.get_vertex_count.times do |i|
|
64
|
+
v = box2d.vector_world_to_pixels(ps.get_vertex(i))
|
65
|
+
vertex(v.x, v.y)
|
66
|
+
end
|
67
|
+
end_shape(CLOSE)
|
68
|
+
pop_matrix
|
69
|
+
end
|
70
|
+
|
71
|
+
# This function adds the rectangle to the box2d world
|
72
|
+
def make_body(center)
|
73
|
+
|
74
|
+
# Define a polygon (this is what we use for a rectangle)
|
75
|
+
sd = B2D::PolygonShape.new
|
76
|
+
|
77
|
+
vertices = []
|
78
|
+
vertices << box2d.vector_pixels_to_world(B2D::Vec2.new(-15, 25))
|
79
|
+
vertices << box2d.vector_pixels_to_world(B2D::Vec2.new(15, 0))
|
80
|
+
vertices << box2d.vector_pixels_to_world(B2D::Vec2.new(20, -15))
|
81
|
+
vertices << box2d.vector_pixels_to_world(B2D::Vec2.new(-10, -10))
|
82
|
+
sd.set(vertices.to_java(Java::OrgJbox2dCommon::Vec2), vertices.length)
|
83
|
+
|
84
|
+
# Define the body and make it from the shape
|
85
|
+
bd = B2D::BodyDef.new
|
86
|
+
bd.type = B2D::BodyType::DYNAMIC
|
87
|
+
bd.position.set(box2d.coord_pixels_to_world(center))
|
88
|
+
@body = box2d.create_body(bd)
|
89
|
+
|
90
|
+
body.create_fixture(sd, 1.0)
|
91
|
+
|
92
|
+
|
93
|
+
# Give it some initial random velocity
|
94
|
+
body.set_linear_velocity(Vec2.new(rand(-5 .. 5), rand(2 .. 5)))
|
95
|
+
body.set_angular_velocity(rand(-5 .. 5))
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# The Nature of Code
|
100
|
+
# <http://www.shiffman.net/teaching/nature>
|
101
|
+
# Spring 2012
|
102
|
+
# PBox2D example
|
103
|
+
|
104
|
+
# A fixed boundary class (now incorporates angle)
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
class Boundary
|
109
|
+
|
110
|
+
attr_reader :box2d, :b, :x, :y, :w, :h #, :a
|
111
|
+
|
112
|
+
def initialize(b2d, x, y, w, h, a)
|
113
|
+
@box2d = b2d
|
114
|
+
@x = x
|
115
|
+
@y = y
|
116
|
+
@w = w
|
117
|
+
@h = h
|
118
|
+
|
119
|
+
# Define the polygon
|
120
|
+
sd = B2D::PolygonShape.new
|
121
|
+
|
122
|
+
# Figure out the box2d coordinates
|
123
|
+
box2dW = box2d.scalar_pixels_to_world(w/2)
|
124
|
+
box2dH = box2d.scalar_pixels_to_world(h/2)
|
125
|
+
# We're just a box
|
126
|
+
sd.set_as_box(box2dW, box2dH)
|
127
|
+
|
128
|
+
|
129
|
+
# Create the body
|
130
|
+
bd = B2D::BodyDef.new
|
131
|
+
bd.type = B2D::BodyType::STATIC
|
132
|
+
bd.angle = a
|
133
|
+
bd.position.set(box2d.coord_pixels_to_world(x,y))
|
134
|
+
@b = box2d.create_body(bd)
|
135
|
+
|
136
|
+
# Attached the shape to the body using a Fixture
|
137
|
+
b.create_fixture(sd,1)
|
138
|
+
end
|
139
|
+
|
140
|
+
# Draw the boundary, it doesn't move so we don't have to ask the Body for location
|
141
|
+
def display
|
142
|
+
fill(0)
|
143
|
+
stroke(0)
|
144
|
+
stroke_weight(1)
|
145
|
+
rect_mode(CENTER)
|
146
|
+
a = b.get_angle
|
147
|
+
push_matrix
|
148
|
+
translate(x,y)
|
149
|
+
rotate(-a)
|
150
|
+
rect(0,0,w,h)
|
151
|
+
pop_matrix
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
|
158
|
+
|