ruby-processing 2.4.3 → 2.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/CHANGELOG +5 -0
- data/README.md +4 -2
- data/lib/ruby-processing/exporters/application_exporter.rb +1 -0
- data/lib/ruby-processing/version.rb +1 -1
- data/library/boids/boids.rb +14 -13
- data/library/vecmath/lib/vec.rb +20 -4
- data/samples/contributed/circle_collision.rb +92 -149
- data/samples/contributed/drawolver.rb +13 -27
- data/samples/contributed/elegant_ball.rb +158 -0
- data/samples/contributed/fern.rb +16 -3
- data/samples/contributed/flight_patterns.rb +16 -4
- data/samples/external_library/java_processing/{pbox2d → box2d_processing}/bumpy_surface_noise.rb +4 -9
- data/samples/external_library/java_processing/{pbox2d → box2d_processing}/data/java_args.txt +0 -0
- data/samples/external_library/java_processing/{pbox2d → box2d_processing}/library/custom_shape/custom_shape.rb +1 -1
- data/samples/external_library/java_processing/{pbox2d → box2d_processing}/library/particle_system/particle_system.rb +7 -10
- data/samples/external_library/java_processing/{pbox2d → box2d_processing}/library/surface/surface.rb +2 -2
- data/samples/external_library/java_processing/{pbox2d → box2d_processing}/liquidy.rb +7 -7
- data/samples/external_library/java_processing/{pbox2d → box2d_processing}/polygons.rb +4 -9
- data/samples/external_library/java_processing/custom/README.md +15 -0
- data/samples/external_library/java_processing/custom/Rakefile +28 -0
- data/samples/external_library/java_processing/custom/landscape.rb +58 -0
- data/samples/external_library/java_processing/custom/src/nn/Connection.java +47 -0
- data/samples/external_library/java_processing/custom/src/nn/HiddenNeuron.java +20 -0
- data/samples/external_library/java_processing/custom/src/nn/InputNeuron.java +23 -0
- data/samples/external_library/java_processing/custom/src/nn/Network.java +136 -0
- data/samples/external_library/java_processing/custom/src/nn/Neuron.java +79 -0
- data/samples/external_library/java_processing/custom/src/nn/OutputNeuron.java +7 -0
- data/samples/external_library/java_processing/custom/xor.rb +88 -0
- data/samples/external_library/ruby_gem/README +1 -1
- data/samples/external_library/ruby_gem/data/data.json +8 -0
- data/samples/external_library/ruby_gem/draw_test.rb +171 -0
- data/samples/processing_app/basics/form/icosahedra.rb +39 -0
- data/samples/processing_app/basics/form/library/icosahedron/icosahedron.rb +60 -0
- data/samples/processing_app/basics/form/toroid.rb +78 -92
- data/samples/processing_app/basics/transform/birds.rb +6 -12
- data/samples/processing_app/basics/transform/cubes_in_cube.rb +25 -22
- data/samples/processing_app/basics/transform/library/cube/cube.rb +16 -16
- data/samples/processing_app/basics/transform/rotate_push_pop.rb +1 -1
- data/samples/processing_app/demos/graphics/bezier_patch.rb +18 -31
- data/samples/processing_app/demos/graphics/trefoil.rb +15 -15
- data/samples/processing_app/library/vecmath/acceleration_with_vectors.rb +3 -3
- data/samples/processing_app/library/vecmath/hilbert_fractal.rb +2 -2
- data/samples/processing_app/library/vecmath/library/flock/flock.rb +18 -21
- data/samples/processing_app/library/vecmath/library/hilbert/hilbert.rb +11 -8
- data/samples/processing_app/library/vecmath/library/wiggler/wiggler.rb +7 -15
- data/samples/processing_app/library/vecmath/seeking_neural.rb +172 -0
- data/samples/processing_app/topics/animation/animated_sprite.rb +5 -8
- data/samples/processing_app/topics/animation/sequential.rb +2 -3
- data/samples/processing_app/topics/create_shapes/library/particle/particle_system.rb +7 -7
- data/samples/processing_app/topics/create_shapes/particle_system_pshape.rb +2 -2
- data/samples/processing_app/topics/create_shapes/wiggle_pshape.rb +2 -1
- data/samples/processing_app/topics/lsystems/koch.rb +1 -1
- data/samples/processing_app/topics/lsystems/library/koch/koch_fractal.rb +24 -23
- data/samples/processing_app/topics/motion/circle_collision.rb +117 -160
- data/samples/processing_app/topics/motion/library/cube/cube.rb +1 -1
- data/samples/processing_app/topics/motion/morph.rb +1 -1
- data/samples/processing_app/topics/motion/reflection1.rb +17 -16
- data/samples/processing_app/topics/shaders/conway.rb +2 -2
- data/samples/processing_app/topics/shaders/data/conway.glsl +10 -10
- data/samples/processing_app/topics/shaders/glsl_heightmap_noise.rb +9 -8
- data/samples/processing_app/topics/shaders/landscape.rb +1 -1
- data/samples/processing_app/topics/simulate/flocking.rb +1 -1
- data/samples/processing_app/topics/simulate/library/flock/flock.rb +62 -57
- data/samples/processing_app/topics/simulate/multiple_particle_systems.rb +8 -28
- data/samples/processing_app/topics/simulate/simple_particle_system.rb +9 -7
- data/samples/processing_app/topics/simulate/smoke_particle_system.rb +12 -11
- data/vendors/Rakefile +2 -2
- metadata +26 -21
- data/samples/contributed/pong.rb +0 -177
- data/samples/contributed/simple_buffer.rb +0 -44
- data/samples/external_library/java_processing/pbox2d/contact_test.rb +0 -23
- data/samples/processing_app/basics/form/icosahedra/icosahedra.rb +0 -72
- data/samples/processing_app/basics/form/icosahedra/icosahedron.rb +0 -116
- data/samples/processing_app/basics/form/icosahedra/shape_3D.rb +0 -25
@@ -1,33 +1,17 @@
|
|
1
1
|
# Drawolver: draw 2D & revolve 3D
|
2
2
|
|
3
|
-
#
|
4
|
-
# replacement for PVector
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
3
|
+
# Example to show how to use the VecMath library.
|
4
|
+
# ruby replacement for PVector. Also features
|
5
|
+
# the use each_cons, possibly a rare use for this
|
6
|
+
# ruby Enumerable method?
|
7
|
+
# 2010-03-22 - fjenett (last revised by monkstone 2014-03-21)
|
8
|
+
# now uses 'zip' and 'each', in place of a custom Array object
|
9
|
+
# with a 'one_of_each' method
|
10
10
|
|
11
11
|
load_library :vecmath
|
12
|
-
|
12
|
+
import 'vecmath'
|
13
13
|
attr_reader :drawing_mode, :points, :rot_x, :rot_y, :vertices
|
14
14
|
|
15
|
-
module ExtendedArray
|
16
|
-
# send one item from each array, expects array to be 2D:
|
17
|
-
# array [[1,2,3], [a,b,c]] sends
|
18
|
-
# [1,a] , [2,b] , [3,c]
|
19
|
-
def one_of_each( &block )
|
20
|
-
i = 0
|
21
|
-
one = self[0]
|
22
|
-
two = self[1]
|
23
|
-
mi = one.length > two.length ? two.length : one.length
|
24
|
-
while i < mi do
|
25
|
-
yield( one[i], two[i] )
|
26
|
-
i += 1
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
15
|
def setup
|
32
16
|
size 1024, 768, P3D
|
33
17
|
frame_rate 30
|
@@ -55,8 +39,7 @@ def draw
|
|
55
39
|
ambient_light 120, 120, 120
|
56
40
|
vertices.each_cons(2) do |r1, r2|
|
57
41
|
begin_shape(TRIANGLE_STRIP)
|
58
|
-
|
59
|
-
ext_array.one_of_each do |v1, v2|
|
42
|
+
r1.zip(r2).each do |v1, v2|
|
60
43
|
vertex v1.x, v1.y, v1.z
|
61
44
|
vertex v2.x, v2.y, v2.z
|
62
45
|
end
|
@@ -94,7 +77,7 @@ def recalculate_shape
|
|
94
77
|
b.normalize!
|
95
78
|
a = ps - points.first
|
96
79
|
dot = a.dot b
|
97
|
-
b
|
80
|
+
b = b * dot
|
98
81
|
normal = points.first + b
|
99
82
|
c = ps - normal
|
100
83
|
# nlen = c.mag
|
@@ -108,3 +91,6 @@ def recalculate_shape
|
|
108
91
|
@drawing_mode = false
|
109
92
|
end
|
110
93
|
|
94
|
+
|
95
|
+
|
96
|
+
|
@@ -0,0 +1,158 @@
|
|
1
|
+
# elegant_ball.rb
|
2
|
+
# After a vanilla processing sketch by
|
3
|
+
# Ben Notorianni aka lazydog
|
4
|
+
#
|
5
|
+
|
6
|
+
load_library :vecmath
|
7
|
+
|
8
|
+
def setup
|
9
|
+
size(800, 800, P3D)
|
10
|
+
color_mode(RGB, 1)
|
11
|
+
end
|
12
|
+
|
13
|
+
def draw
|
14
|
+
#background(0.25)
|
15
|
+
background(0)
|
16
|
+
# Move the origin so that the scene is centered on the screen.
|
17
|
+
translate(width/2, height/2, 0.0)
|
18
|
+
# Set up the lighting.
|
19
|
+
setup_lights
|
20
|
+
# Rotate the local coordinate system.
|
21
|
+
smooth_rotation(5.0, 6.7, 7.3)
|
22
|
+
# Draw the inner object.
|
23
|
+
no_stroke
|
24
|
+
fill(smooth_colour(10.0, 12.0, 7.0))
|
25
|
+
draw_icosahedron(5, 60.0, false)
|
26
|
+
# Rotate the local coordinate system again.
|
27
|
+
smooth_rotation(4.5, 3.7, 7.3)
|
28
|
+
# Draw the outer object.
|
29
|
+
stroke(0.2)
|
30
|
+
fill(smooth_colour(6.0, 9.2, 0.7))
|
31
|
+
draw_icosahedron(5, 200.0, true)
|
32
|
+
end
|
33
|
+
|
34
|
+
def setup_lights
|
35
|
+
ambient_light(0.025, 0.025, 0.025)
|
36
|
+
directional_light(0.2, 0.2, 0.2, -1, -1, -1)
|
37
|
+
spot_light(1.0, 1.0, 1.0, -200, 0, 300, 1, 0, -1, PI/4, 20)
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
# Generate a vector whose components change smoothly over time in the range [ 0, 1 ].
|
42
|
+
# Each component uses a Math.sin function to map the current time in milliseconds somewhere
|
43
|
+
# in the range [ 0, 1 ].A 'speed' factor is specified for each component.
|
44
|
+
#
|
45
|
+
def smooth_vector(s1, s2, s3)
|
46
|
+
mills = millis * 0.00003
|
47
|
+
rot = ->(a){0.5 * Math.sin(mills * a) + 0.5}
|
48
|
+
Vec3D.new(rot.call(s1), rot.call(s2), rot.call(s3))
|
49
|
+
end
|
50
|
+
|
51
|
+
##
|
52
|
+
# Generate a colour which smoothly changes over time.
|
53
|
+
# The speed of each component is controlled by the parameters s1, s2 and s3.
|
54
|
+
#
|
55
|
+
def smooth_colour(s1, s2, s3)
|
56
|
+
v = smooth_vector(s1, s2, s3)
|
57
|
+
color(v.x, v.y, v.z)
|
58
|
+
end
|
59
|
+
|
60
|
+
##
|
61
|
+
# Rotate the current coordinate system.
|
62
|
+
# Uses smooth_vector to smoothly animate the rotation.
|
63
|
+
#
|
64
|
+
def smooth_rotation(s1, s2, s3)
|
65
|
+
r1 = smooth_vector(s1, s2, s3)
|
66
|
+
rotate_x(2.0 * PI * r1.x)
|
67
|
+
rotate_y(2.0 * PI * r1.y)
|
68
|
+
rotate_x(2.0 * PI * r1.z)
|
69
|
+
end
|
70
|
+
|
71
|
+
##
|
72
|
+
# Draw an icosahedron defined by a radius r and recursive depth d.
|
73
|
+
# Geometry data will be saved into dst. If spherical is true then the icosahedron
|
74
|
+
# is projected onto the sphere with radius r.
|
75
|
+
#
|
76
|
+
def draw_icosahedron(depth, r, spherical)
|
77
|
+
# Calculate the vertex data for an icosahedron inscribed by a sphere radius 'r'.
|
78
|
+
# Use 4 Golden Ratio rectangles as the basis.
|
79
|
+
gr = (1.0 + Math.sqrt(5.0)) / 2.0
|
80
|
+
h = r / Math.sqrt(1.0 + gr * gr)
|
81
|
+
v =
|
82
|
+
[
|
83
|
+
Vec3D.new(0, -h, h*gr), Vec3D.new(0, -h, -h*gr), Vec3D.new(0, h, -h*gr), Vec3D.new(0, h, h*gr),
|
84
|
+
Vec3D.new(h, -h*gr, 0), Vec3D.new(h, h*gr, 0), Vec3D.new(-h, h*gr, 0), Vec3D.new(-h, -h*gr, 0),
|
85
|
+
Vec3D.new(-h*gr, 0, h), Vec3D.new(-h*gr, 0, -h), Vec3D.new(h*gr, 0, -h), Vec3D.new(h*gr, 0, h)
|
86
|
+
]
|
87
|
+
|
88
|
+
# Draw the 20 triangular faces of the icosahedron.
|
89
|
+
unless spherical then
|
90
|
+
r = 0.0
|
91
|
+
end
|
92
|
+
|
93
|
+
begin_shape(TRIANGLES)
|
94
|
+
|
95
|
+
draw_triangle(depth, r, v[0], v[7],v[4])
|
96
|
+
draw_triangle(depth, r, v[0], v[4], v[11])
|
97
|
+
draw_triangle(depth, r, v[0], v[11], v[3])
|
98
|
+
draw_triangle(depth, r, v[0], v[3], v[8])
|
99
|
+
draw_triangle(depth, r, v[0], v[8], v[7])
|
100
|
+
|
101
|
+
draw_triangle(depth, r, v[1], v[4], v[7])
|
102
|
+
draw_triangle(depth, r, v[1], v[10], v[4])
|
103
|
+
draw_triangle(depth, r, v[10], v[11], v[4])
|
104
|
+
draw_triangle(depth, r, v[11], v[5], v[10])
|
105
|
+
draw_triangle(depth, r, v[5], v[3], v[11])
|
106
|
+
draw_triangle(depth, r, v[3], v[6], v[5])
|
107
|
+
draw_triangle(depth, r, v[6], v[8], v[3])
|
108
|
+
draw_triangle(depth, r, v[8], v[9], v[6])
|
109
|
+
draw_triangle(depth, r, v[9], v[7], v[8])
|
110
|
+
draw_triangle(depth, r, v[7], v[1], v[9])
|
111
|
+
|
112
|
+
draw_triangle(depth, r, v[2], v[1], v[9])
|
113
|
+
draw_triangle(depth, r, v[2], v[10], v[1])
|
114
|
+
draw_triangle(depth, r, v[2], v[5], v[10])
|
115
|
+
draw_triangle(depth, r, v[2], v[6], v[5])
|
116
|
+
draw_triangle(depth, r, v[2], v[9], v[6])
|
117
|
+
|
118
|
+
end_shape
|
119
|
+
end
|
120
|
+
|
121
|
+
##
|
122
|
+
# Draw a triangle either immediately or subdivide it first.
|
123
|
+
# If depth is 1 then draw the triangle otherwise subdivide first.
|
124
|
+
#
|
125
|
+
def draw_triangle(depth, r, p1, p2, p3)
|
126
|
+
|
127
|
+
if (depth == 1) then
|
128
|
+
vertex(p1.x, p1.y, p1.z)
|
129
|
+
vertex(p2.x, p2.y, p2.z)
|
130
|
+
vertex(p3.x, p3.y, p3.z)
|
131
|
+
else
|
132
|
+
# Calculate the mid points of this triangle.
|
133
|
+
v1 = (p1 + p2) * 0.5
|
134
|
+
v2 = (p2 + p3) * 0.5
|
135
|
+
v3 = (p3 + p1) * 0.5
|
136
|
+
unless (r == 0.0) then
|
137
|
+
# Project the verticies out onto the sphere with radius r.
|
138
|
+
v1.normalize!
|
139
|
+
v1 *= r
|
140
|
+
v2.normalize!
|
141
|
+
v2 *= r
|
142
|
+
v3.normalize!
|
143
|
+
v3 *= r
|
144
|
+
end
|
145
|
+
## Generate the next level of detail
|
146
|
+
depth -= 1
|
147
|
+
draw_triangle(depth, r, p1, v1, v3)
|
148
|
+
draw_triangle(depth, r, v1, p2, v2)
|
149
|
+
draw_triangle(depth, r, v2, p3, v3)
|
150
|
+
# Uncomment out the next line to include the central part of the triangle.
|
151
|
+
# draw_triangle(depth, r, v1, v2, v3)
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
|
data/samples/contributed/fern.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
# The Fern Fractal
|
2
2
|
# by Luis Correia
|
3
|
+
|
4
|
+
attr_reader :boundary
|
3
5
|
|
4
6
|
def setup
|
5
7
|
size 500, 500
|
8
|
+
@boundary = Boundary.new(0, width )
|
6
9
|
no_loop
|
7
10
|
puts "Be patient. This takes about 10 seconds to render."
|
8
11
|
end
|
@@ -16,7 +19,7 @@ def draw
|
|
16
19
|
max_iterations = 200000
|
17
20
|
|
18
21
|
max_iterations.times do
|
19
|
-
r = rand(100.0)
|
22
|
+
r = rand(0 .. 100.0)
|
20
23
|
if r <= 1
|
21
24
|
x = 0.0
|
22
25
|
y = 0.16 * y0
|
@@ -33,9 +36,19 @@ def draw
|
|
33
36
|
|
34
37
|
i = height - (y * 45).to_i
|
35
38
|
j = width / 2 + (x * 45).to_i
|
36
|
-
pixels[i * height + j] += 2560 if (i
|
39
|
+
pixels[i * height + j] += 2560 if (boundary.include?(i) && boundary.include?(j))
|
37
40
|
x0, y0 = x, y
|
38
41
|
end
|
39
42
|
|
40
43
|
update_pixels
|
41
|
-
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Abstract boundary checking to this
|
47
|
+
# lightweight class
|
48
|
+
#
|
49
|
+
|
50
|
+
Boundary = Struct.new(:lower, :upper) do
|
51
|
+
def include? x
|
52
|
+
(lower ... upper).cover? x
|
53
|
+
end
|
54
|
+
end
|
@@ -29,9 +29,6 @@ end
|
|
29
29
|
|
30
30
|
def draw
|
31
31
|
background 0.05
|
32
|
-
ambient_light 0.01, 0.01, 0.01
|
33
|
-
light_specular 0.4, 0.2, 0.2
|
34
|
-
point_light 1.0, 1.0, 1.0, mouse_x, mouse_y, width / 4.0
|
35
32
|
@flocks.each_with_index do |flock, i|
|
36
33
|
flock.goal mouse_x, mouse_y, 0, @flee
|
37
34
|
flock.update(goal: 185, limit: 13.5)
|
@@ -44,8 +41,23 @@ def draw
|
|
44
41
|
end
|
45
42
|
push_matrix
|
46
43
|
translate boid.x-r/2, boid.y-r/2, boid.z-r/2
|
47
|
-
@click
|
44
|
+
if @click
|
45
|
+
lights_on
|
46
|
+
hint ENABLE_DEPTH_TEST
|
47
|
+
sphere(r/2)
|
48
|
+
else
|
49
|
+
no_lights
|
50
|
+
hint DISABLE_DEPTH_TEST
|
51
|
+
oval(0, 0, r, r)
|
52
|
+
end
|
48
53
|
pop_matrix
|
49
54
|
end
|
50
55
|
end
|
51
56
|
end
|
57
|
+
|
58
|
+
def lights_on
|
59
|
+
lights
|
60
|
+
ambient_light 0.01, 0.01, 0.01
|
61
|
+
light_specular 0.4, 0.2, 0.2
|
62
|
+
point_light 1.0, 1.0, 1.0, mouse_x, mouse_y, width / 4.0
|
63
|
+
end
|
data/samples/external_library/java_processing/{pbox2d → box2d_processing}/bumpy_surface_noise.rb
RENAMED
@@ -1,12 +1,11 @@
|
|
1
1
|
# The Nature of Code
|
2
|
-
# <http
|
2
|
+
# <http://www.shiffman.net/teaching/nature>
|
3
3
|
# Spring 2010
|
4
4
|
# PBox2D example
|
5
5
|
|
6
6
|
# An uneven surface
|
7
7
|
|
8
|
-
|
9
|
-
load_library :surface
|
8
|
+
load_libraries :box2d_processing, :surface
|
10
9
|
|
11
10
|
include SB
|
12
11
|
|
@@ -17,7 +16,7 @@ def setup
|
|
17
16
|
smooth
|
18
17
|
|
19
18
|
# Initialize box2d physics and create the world
|
20
|
-
@box2d =
|
19
|
+
@box2d = SB::Box2DProcessing.new(self)
|
21
20
|
box2d.create_world
|
22
21
|
# We are setting a custom gravity
|
23
22
|
box2d.set_gravity(0, -20)
|
@@ -46,11 +45,7 @@ def draw
|
|
46
45
|
end
|
47
46
|
# Particles that leave the screen, we delete them
|
48
47
|
# (note they have to be deleted from both the box2d world and our list
|
49
|
-
particles.
|
50
|
-
if (p.done)
|
51
|
-
particles.delete_at(i)
|
52
|
-
end
|
53
|
-
end
|
48
|
+
particles.reject! {|p| p.done}
|
54
49
|
# Just drawing the framerate to see how many particles it can handle
|
55
50
|
fill(0)
|
56
51
|
text("framerate: #{frame_rate.to_i}", 12, 16)
|
data/samples/external_library/java_processing/{pbox2d → box2d_processing}/data/java_args.txt
RENAMED
File without changes
|
@@ -2,22 +2,22 @@ module PS
|
|
2
2
|
include_package 'org.jbox2d.collision.shapes'
|
3
3
|
include_package 'org.jbox2d.common'
|
4
4
|
include_package 'org.jbox2d.dynamics'
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
include_package 'shiffman.box2d'
|
6
|
+
|
8
7
|
# Box2D Particle System
|
9
8
|
# <http://www.shiffman.net/teaching/nature>
|
10
9
|
# Spring 2010
|
10
|
+
# translated to ruby-processing Martin Prout
|
11
11
|
|
12
12
|
# A class to describe a group of Particles
|
13
|
-
# An
|
13
|
+
# An Array is used to manage the list of Particles
|
14
14
|
|
15
15
|
class ParticleSystem
|
16
16
|
|
17
17
|
attr_reader :particles, :x, :y
|
18
18
|
|
19
19
|
def initialize(bd, num, x, y)
|
20
|
-
@particles = [] # Initialize the
|
20
|
+
@particles = [] # Initialize the Array
|
21
21
|
@x, @y = x, y # Store the origin point
|
22
22
|
num.times do
|
23
23
|
particles << PS::Particle.new(bd, x, y)
|
@@ -32,11 +32,8 @@ module PS
|
|
32
32
|
# Particles that leave the screen, we delete them
|
33
33
|
# (note they have to be deleted from both the box2d world and our list
|
34
34
|
|
35
|
-
particles.
|
36
|
-
|
37
|
-
particles.delete_at(i)
|
38
|
-
end
|
39
|
-
end
|
35
|
+
particles.reject! { |p| p.done}
|
36
|
+
|
40
37
|
end
|
41
38
|
|
42
39
|
def add_particles(bd, n)
|
data/samples/external_library/java_processing/{pbox2d → box2d_processing}/library/surface/surface.rb
RENAMED
@@ -1,5 +1,5 @@
|
|
1
1
|
# The Nature of Code
|
2
|
-
# <http
|
2
|
+
# <http://www.shiffman.net/teaching/nature>
|
3
3
|
# Spring 2010
|
4
4
|
# PBox2D example
|
5
5
|
|
@@ -9,7 +9,7 @@ module SB
|
|
9
9
|
include_package 'org.jbox2d.collision.shapes'
|
10
10
|
include_package 'org.jbox2d.common'
|
11
11
|
include_package 'org.jbox2d.dynamics'
|
12
|
-
|
12
|
+
include_package 'shiffman.box2d'
|
13
13
|
|
14
14
|
|
15
15
|
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# The Nature of Code
|
2
2
|
# <http:#www.shiffman.net/teaching/nature>
|
3
3
|
# Spring 2011
|
4
|
-
#
|
4
|
+
# Updated to use the updated library
|
5
|
+
# translated to ruby-processing 2 March 2014 by Martin Prout
|
6
|
+
# Box2DProcessing example
|
5
7
|
|
6
|
-
|
8
|
+
load_libraries :box2d_processing, :particle_system
|
7
9
|
|
8
|
-
load_library :pbox2d
|
9
|
-
load_library :particle_system
|
10
10
|
|
11
|
-
# module PS is a wrapper for java
|
11
|
+
# module PS is a wrapper for java packages, and Boundary and Particle classes
|
12
12
|
include PS
|
13
13
|
|
14
14
|
attr_reader :box2d, :boundaries, :systems
|
@@ -17,11 +17,11 @@ def setup
|
|
17
17
|
size(400,300)
|
18
18
|
smooth
|
19
19
|
# Initialize box2d physics and create the world
|
20
|
-
@box2d =
|
20
|
+
@box2d = PS::Box2DProcessing.new(self)
|
21
21
|
box2d.create_world
|
22
22
|
# We are setting a custom gravity
|
23
23
|
box2d.set_gravity(0, -20)
|
24
|
-
# Create
|
24
|
+
# Create Arrays
|
25
25
|
@systems = []
|
26
26
|
@boundaries = []
|
27
27
|
# Add a bunch of fixed boundaries
|
@@ -1,11 +1,10 @@
|
|
1
1
|
# The Nature of Code
|
2
2
|
# <http://www.shiffman.net/teaching/nature>
|
3
3
|
# Spring 2011
|
4
|
-
#
|
4
|
+
# Box2DProcessing example
|
5
5
|
|
6
6
|
# Basic example of falling rectangles
|
7
|
-
|
8
|
-
load_library :custom_shape
|
7
|
+
load_libraries :box2d_processing, :custom_shape
|
9
8
|
|
10
9
|
# module B2D is a wrapper for java imports, and Boundary and CustomShape classes
|
11
10
|
include B2D
|
@@ -16,7 +15,7 @@ def setup
|
|
16
15
|
size(640,360)
|
17
16
|
smooth
|
18
17
|
# Initialize box2d physics and create the world
|
19
|
-
@box2d =
|
18
|
+
@box2d = B2D::Box2DProcessing.new(self)
|
20
19
|
box2d.create_world
|
21
20
|
# We are setting a custom gravity
|
22
21
|
box2d.set_gravity(0, -20)
|
@@ -46,11 +45,7 @@ def draw
|
|
46
45
|
|
47
46
|
# polygons that leave the screen, we delete them
|
48
47
|
# (note they have to be deleted from both the box2d world and our list
|
49
|
-
polygons.
|
50
|
-
if polygon.done
|
51
|
-
polygons.delete_at(i)
|
52
|
-
end
|
53
|
-
end
|
48
|
+
polygons.reject! { |p| p.done}
|
54
49
|
end
|
55
50
|
|
56
51
|
def mouse_pressed
|