pbox2d 0.4.2-java → 0.5.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +15 -0
  3. data/CHANGELOG.md +37 -0
  4. data/CONTRIBUTING.md +30 -0
  5. data/Gemfile +4 -0
  6. data/LICENCE +25 -0
  7. data/LICENSE.md +1 -3
  8. data/README.md +3 -3
  9. data/Rakefile +19 -81
  10. data/examples/README.md +7 -0
  11. data/examples/bumpy_surface_noise.rb +11 -7
  12. data/examples/collision_listening.rb +30 -0
  13. data/examples/data/java_args.txt +2 -0
  14. data/examples/distance_joint/distance_joint.rb +8 -5
  15. data/examples/lib/boundary.rb +22 -13
  16. data/examples/lib/box.rb +1 -2
  17. data/examples/lib/custom_listener.rb +29 -0
  18. data/examples/lib/custom_shape.rb +5 -3
  19. data/examples/lib/particle.rb +77 -0
  20. data/examples/lib/particle_system.rb +25 -65
  21. data/examples/lib/shape_system.rb +5 -3
  22. data/examples/lib/surface.rb +1 -1
  23. data/examples/liquid_fun_test.rb +11 -5
  24. data/examples/liquidy.rb +18 -14
  25. data/examples/mouse_joint/boundary.rb +1 -1
  26. data/examples/mouse_joint/box.rb +1 -1
  27. data/examples/mouse_joint/dummy_spring.rb +2 -3
  28. data/examples/mouse_joint/mouse_joint.rb +7 -8
  29. data/examples/polygons.rb +16 -16
  30. data/examples/quick_test.rb +33 -63
  31. data/examples/revolute_joint/revolute_joint.rb +5 -1
  32. data/examples/test_contact/README.md +6 -0
  33. data/examples/test_contact/lib/boundary.rb +1 -1
  34. data/examples/test_contact/lib/particle.rb +3 -3
  35. data/examples/test_contact/test_contact.rb +2 -1
  36. data/lib/box2d.jar +0 -0
  37. data/lib/jbox2d-library-2.3.1-SNAPSHOT.jar +0 -0
  38. data/lib/pbox2d/box2d.rb +1 -1
  39. data/lib/pbox2d/version.rb +2 -3
  40. data/pbox2d.gemspec +33 -0
  41. data/pom.xml +146 -0
  42. data/src/processing/box2d/Box2DProcessing.java +319 -0
  43. data/src/processing/box2d/Options.java +52 -0
  44. data/src/processing/box2d/Step.java +44 -0
  45. metadata +46 -34
  46. data/lib/jbox2d-library-2.2.1-ds.jar +0 -0
@@ -2,8 +2,8 @@ require 'forwardable'
2
2
 
3
3
  module Runnable
4
4
  def run
5
- reject!(&:done)
6
- each(&:display)
5
+ reject! { |item| item.done }
6
+ each { |item| item.display }
7
7
  end
8
8
  end
9
9
 
@@ -14,15 +14,19 @@ class ParticleSystem
14
14
  def_delegator(:@particles, :empty?, :dead?)
15
15
 
16
16
  attr_reader :x, :y
17
-
18
- def initialize(app, num, x, y)
19
- @x, @y = x, y # Store the origin point
20
- # initialize array with some particles
21
- @particles = Array.new(num, Particle.new(app, x, y))
17
+
18
+ def initialize(bd, num, x, y)
19
+ @particles = [] # Initialize the Array
20
+ @x, @y = x, y # Store the origin point
21
+ num.times do
22
+ self << Particle.new(bd, x, y)
23
+ end
22
24
  end
23
-
24
- def add_particles(app, n)
25
- n.times { self << Particle.new(app, x, y) }
25
+
26
+ def add_particles(bd, n)
27
+ n.times do
28
+ self << Particle.new(bd, x, y)
29
+ end
26
30
  end
27
31
  end
28
32
 
@@ -30,40 +34,37 @@ end
30
34
  require 'pbox2d'
31
35
 
32
36
  class Particle
33
- extend Forwardable
34
- def_delegators(:@app, :box2d, :begin_shape, :end_shape,
35
- :vertex, :translate, :rotate, :stroke,
36
- :fill, :no_fill, :stroke_weight)
37
+ include Processing::Proxy
37
38
  TRAIL_SIZE = 6
38
39
  # We need to keep track of a Body
39
-
40
- attr_reader :trail, :body
41
-
40
+
41
+ attr_reader :trail, :body, :box2d
42
+
42
43
  # Constructor
43
- def initialize(app, x, y)
44
- @app = app
44
+ def initialize(b2d, x, y)
45
+ @box2d = b2d
45
46
  @trail = Array.new(TRAIL_SIZE, [x, y])
46
47
  # Add the box to the box2d world
47
48
  # Here's a little trick, let's make a tiny tiny radius
48
49
  # This way we have collisions, but they don't overwhelm the system
49
50
  make_body(x, y, 0.2)
50
51
  end
51
-
52
+
52
53
  # This function removes the particle from the box2d world
53
54
  def kill_body
54
55
  box2d.destroy_body(body)
55
56
  end
56
-
57
+
57
58
  # Is the particle ready for deletion?
58
59
  def done
59
60
  # Let's find the screen position of the particle
60
61
  pos = box2d.body_coord(body)
61
62
  # Is it off the bottom of the screen?
62
- return false unless pos.y > box2d.height + 20
63
+ return false unless (pos.y > box2d.height + 20)
63
64
  kill_body
64
65
  true
65
66
  end
66
-
67
+
67
68
  # Drawing the box
68
69
  def display
69
70
  # We look at each body and get its screen position
@@ -83,7 +84,7 @@ class Particle
83
84
  end
84
85
  end_shape
85
86
  end
86
-
87
+
87
88
  # This function adds the rectangle to the box2d world
88
89
  def make_body(x, y, r)
89
90
  # Define and create the body
@@ -107,44 +108,3 @@ class Particle
107
108
  body.create_fixture(fd)
108
109
  end
109
110
  end
110
-
111
- class Boundary
112
- extend Forwardable
113
- def_delegators(:@app, :box2d, :push_matrix, :pop_matrix, :stroke, :width,
114
- :vertex, :translate, :rotate, :rect_mode, :rect,
115
- :fill, :no_fill, :stroke_weight)
116
- attr_reader :b, :x, :y, :h
117
-
118
- def initialize(app, x, y, h, a)
119
- @app, @x, @y, @h = app, x, y, h
120
- # Define the polygon
121
- sd = PolygonShape.new
122
- # Figure out the box2d coordinates
123
- box2d_w = box2d.scale_to_world(width / 2)
124
- box2d_h = box2d.scale_to_world(h / 2)
125
- # We're just a box
126
- sd.set_as_box(box2d_w, box2d_h)
127
- # Create the body
128
- bd = BodyDef.new
129
- bd.type = BodyType::STATIC
130
- bd.angle = a
131
- bd.position.set(box2d.processing_to_world(x, y))
132
- @b = box2d.create_body(bd)
133
- # Attached the shape to the body using a Fixture
134
- b.create_fixture(sd, 1)
135
- end
136
-
137
- # Draw the boundary, it doesn't move so we don't have to ask the Body for location
138
- def display
139
- fill(0)
140
- stroke(0)
141
- stroke_weight(1)
142
- rect_mode(Java::ProcessingCore::PConstants::CENTER)
143
- a = b.get_angle
144
- push_matrix
145
- translate(x, y)
146
- rotate(-a)
147
- rect(0, 0, width, h)
148
- pop_matrix
149
- end
150
- end
@@ -1,6 +1,6 @@
1
1
  module Runnable
2
2
  def run
3
- reject! { |item| item.done? }
3
+ reject! { |item| item.done }
4
4
  each { |item| item.display }
5
5
  end
6
6
  end
@@ -11,13 +11,15 @@ class ShapeSystem
11
11
  def_delegators(:@polygons, :each, :reject!, :<<)
12
12
 
13
13
  attr_reader :bd
14
-
14
+
15
15
  def initialize(bd)
16
16
  @bd = bd
17
17
  @polygons = [] # Initialize the Array
18
18
  end
19
-
19
+
20
20
  def add_polygon(x, y)
21
21
  self << CustomShape.new(bd, x, y)
22
22
  end
23
23
  end
24
+
25
+
@@ -133,4 +133,4 @@ class Particle
133
133
  body.set_linear_velocity(Vec2.new(rand(-10..10), rand(5..10)))
134
134
  body.set_angular_velocity(rand(-10..10))
135
135
  end
136
- end
136
+ end
@@ -9,17 +9,19 @@ require_relative 'lib/box'
9
9
 
10
10
  attr_reader :boxes, :boundaries, :box2d
11
11
 
12
+ Vect = Struct.new(:x, :y)
13
+
12
14
  def setup
13
- size(640, 360, P2D)
15
+ sketch_title 'Liquid Fun Test'
14
16
  @box2d = Box2D.new(self)
15
17
  box2d.init_options(gravity: [0, -10])
16
- box2d.create_world
18
+ box2d.create_world
17
19
  @boxes = []
18
20
  box2d.world.set_particle_radius(0.15)
19
21
  box2d.world.set_particle_damping(0.2)
20
22
  @boundaries = [
21
- Boundary.new(self, width / 4, height - 5, width / 2 - 50, 10),
22
- Boundary.new(self, 3 * width / 4, height - 50, width / 2 - 50, 10)
23
+ Boundary.new(box2d, Vect.new(width / 4, height - 5), Vect.new(width / 2 - 50, 10)),
24
+ Boundary.new(box2d, Vect.new(3 * width / 4, height - 50), Vect.new(width / 2 - 50, 10))
23
25
  ]
24
26
  end
25
27
 
@@ -39,5 +41,9 @@ def draw
39
41
  point(pos.x, pos.y)
40
42
  end
41
43
  fill(0)
42
- text(format('f.p.s %d', frame_rate.to_i), 10, 60)
44
+ text(format('f.p.s %d', frame_rate), 10, 60)
45
+ end
46
+
47
+ def settings
48
+ size(640, 360, P2D)
43
49
  end
data/examples/liquidy.rb CHANGED
@@ -1,36 +1,40 @@
1
1
  require 'pbox2d'
2
2
  require_relative 'lib/particle_system'
3
+ require_relative 'lib/boundary'
3
4
  attr_reader :box2d, :boundaries, :systems
4
5
 
6
+ Vect = Struct.new(:x, :y)
7
+
5
8
  def setup
6
- size(400, 300)
9
+ sketch_title 'Liquidy'
7
10
  @box2d = Box2D.new(self)
8
11
  box2d.init_options(gravity: [0, -20])
9
12
  box2d.create_world
10
- # to set a custom gravity otherwise
11
- # box2d.gravity([0, -20])
12
- # Create Arrays
13
13
  @systems = []
14
14
  @boundaries = [
15
- Boundary.new(self, 50, 100, 5, -0.3),
16
- Boundary.new(self, 250, 175, 5, 0.5)
15
+ Boundary.new(box2d, Vect.new(50, 100), Vect.new(300, 5), -0.3),
16
+ Boundary.new(box2d, Vect.new(250, 175), Vect.new(300, 5), 0.5)
17
17
  ]
18
18
  end
19
19
 
20
20
  def draw
21
21
  background(255)
22
- # Display all the boundaries
23
- boundaries.each(&:display)
24
22
  # Run all the particle systems
25
- return unless systems.size > 0
26
- systems.each do |system|
27
- system.run
28
- # refresh particles (else we'll run out)
29
- system.add_particles(self, rand(0..2))
23
+ if systems.size > 0
24
+ systems.each do |system|
25
+ system.run
26
+ system.add_particles(box2d, rand(0..2))
27
+ end
30
28
  end
29
+ # Display all the boundaries
30
+ boundaries.each(&:display)
31
31
  end
32
32
 
33
33
  def mouse_pressed
34
34
  # Add a new Particle System whenever the mouse is clicked
35
- systems << ParticleSystem.new(self, 0, mouse_x, mouse_y)
35
+ systems << ParticleSystem.new(box2d, 0, mouse_x, mouse_y)
36
+ end
37
+
38
+ def settings
39
+ size(400,300)
36
40
  end
@@ -36,7 +36,7 @@ class Boundary
36
36
  stroke(127)
37
37
  fill(127)
38
38
  stroke_weight(1)
39
- rect_mode(Java::ProcessingCore::PConstants::CENTER)
39
+ rect_mode(Java::ProcessingCore::CENTER)
40
40
  a = b.get_angle
41
41
  push_matrix
42
42
  translate(x, y)
@@ -34,7 +34,7 @@ class Box
34
34
  pos = box2d.body_coord(body)
35
35
  # Get its angle of rotation
36
36
  a = body.getAngle
37
- rect_mode(Java::ProcessingCore::PConstants::CENTER)
37
+ rect_mode(Java::ProcessingCore::CENTER)
38
38
  push_matrix
39
39
  translate(pos.x, pos.y)
40
40
  rotate(a)
@@ -1,14 +1,13 @@
1
1
  # dummy_spring.rb by Martin Prout
2
2
  # An example of duck-typing in ruby-processing
3
3
 
4
- # This class avoids the tests for null seen in vanilla processing version
4
+ # This class avoids the tests for null of the vanilla processing version
5
5
  class DummySpring
6
6
  def initialize; end
7
7
  def update(_x, _y); end
8
8
  def display; end
9
-
10
9
  # This is the key function where
11
- # we attach a real spring between an x, y location
10
+ # we attach the spring to an x,y location
12
11
  # and the box object's location
13
12
  # @param x (will be mouse_x)
14
13
  # @param y (will be mouse_y)
@@ -21,15 +21,14 @@ def setup
21
21
  box2d.create_world
22
22
  # Make the box
23
23
  @box = Box.new(width / 2, height / 2)
24
- # Make a dummy spring, that returns a real spring on :bind
24
+ # Make a dummy spring
25
25
  @spring = DummySpring.new
26
- # Create a bunch of fixed boundaries
27
- @boundaries = [
28
- Boundary.new(width / 2, height - 5, width, 10, 0),
29
- Boundary.new(width / 2, 5, width, 10, 0),
30
- Boundary.new(width - 5, height / 2, 10, height, 0),
31
- Boundary.new(5, height / 2, 10, height, 0)
32
- ]
26
+ # Add a bunch of fixed boundaries
27
+ @boundaries = []
28
+ boundaries << Boundary.new(width / 2, height - 5, width, 10, 0)
29
+ boundaries << Boundary.new(width / 2, 5, width, 10, 0)
30
+ boundaries << Boundary.new(width - 5, height / 2, 10, height, 0)
31
+ boundaries << Boundary.new(5, height / 2, 10, height, 0)
33
32
  end
34
33
 
35
34
  # When the mouse is released we're done with the spring
data/examples/polygons.rb CHANGED
@@ -2,25 +2,24 @@
2
2
  require 'pbox2d'
3
3
  require_relative 'lib/custom_shape'
4
4
  require_relative 'lib/boundary'
5
+ require_relative 'lib/shape_system'
5
6
 
6
- attr_reader :box2d, :boundaries, :polygons
7
+ attr_reader :box2d, :boundaries, :system
8
+
9
+ Vect = Struct.new(:x, :y)
7
10
 
8
11
  def setup
9
- size(640, 360)
12
+ sketch_title 'Polygons'
10
13
  smooth
11
- # Initialize box2d physics and create the world
12
14
  @box2d = Box2D.new(self)
13
15
  box2d.init_options(gravity: [0, -20])
14
16
  box2d.create_world
15
- # To later set a custom gravity
16
- # box2d.gravity([0, -20]
17
- # Create Arrays
18
- @polygons = []
17
+ @system = ShapeSystem.new self
19
18
  @boundaries = [
20
- Boundary.new(self, width / 4, height - 5, width / 2 - 50, 10),
21
- Boundary.new(self, 3 * width / 4, height - 50, width / 2 - 50, 10),
22
- Boundary.new(self, width - 5, height / 2, 10, height),
23
- Boundary.new(self, 5, height / 2, 10, height)
19
+ Boundary.new(box2d, Vect.new(width / 4, height - 5), Vect.new(width / 2 - 50, 10)),
20
+ Boundary.new(box2d, Vect.new(3 * width / 4, height - 50), Vect.new(width / 2 - 50, 10)),
21
+ Boundary.new(box2d, Vect.new(width - 5, height / 2), Vect.new(10, height)),
22
+ Boundary.new(box2d, Vect.new(5, height / 2), Vect.new(10, height))
24
23
  ]
25
24
  end
26
25
 
@@ -29,12 +28,13 @@ def draw
29
28
  # Display all the boundaries
30
29
  boundaries.each(&:display)
31
30
  # Display all the polygons
32
- polygons.each(&:display)
33
- # polygons that leave the screen, we delete them
34
- # (note they have to be deleted from both the box2d world and our list
35
- polygons.reject!(&:done)
31
+ system.run
36
32
  end
37
33
 
38
34
  def mouse_pressed
39
- polygons << CustomShape.new(self, mouse_x, mouse_y)
35
+ system << CustomShape.new(box2d, mouse_x, mouse_y)
36
+ end
37
+
38
+ def settings
39
+ size(640, 360)
40
40
  end
@@ -1,4 +1,5 @@
1
1
  require 'pbox2d'
2
+ require_relative 'lib/boundary'
2
3
 
3
4
  # A list we'll use to track fixed objects
4
5
  attr_reader :box2d, :boundaries, :boxes
@@ -6,8 +7,10 @@ attr_reader :box2d, :boundaries, :boxes
6
7
  java_alias :background_int, :background, [Java::int]
7
8
  java_alias :stroke_int, :stroke, [Java::int]
8
9
 
10
+ Vect = Struct.new(:x, :y)
11
+
9
12
  def setup
10
- size(400,300)
13
+ sketch_title 'Quick Test'
11
14
  stroke_int(0) # set stroke this way to avoid overload warnings
12
15
  srand(5)
13
16
  # Initialize box2d physics and create the world
@@ -16,79 +19,42 @@ def setup
16
19
  box2d.init_options(scale: 10, gravity: [0, -20.0])
17
20
  box2d.create_world
18
21
  # Set a custom gravity
19
- # box2d.gravity(0, -20)
20
- # Create ArrayLists
22
+ # box2d.gravity(0, -20)
23
+ # Create ArrayLists
21
24
  @boxes = []
22
25
  @boundaries = [
23
- Boundary.new(self, width / 4, height - 5, width / 2 - 50, 10),
24
- Boundary.new(self, 3 * width / 4, height - 50, width / 2 - 50, 10)
26
+ Boundary.new(box2d, Vect.new(width / 4, height - 5), Vect.new(width / 2 - 50, 10)),
27
+ Boundary.new(box2d, Vect.new(3 * width / 4, height - 50), Vect.new(width / 2 - 50, 10))
25
28
  ]
26
29
  end
27
30
 
28
31
  def draw
29
- background_int(255) # set background this way to avoid overload warnings
32
+ background_int(255) # set background this way to avoid overload warnings
30
33
  # Boxes fall from the top every so often
31
- boxes << Box.new(self, width / 2, 30) if rand < 0.99
32
- boundaries.each(&:display)
33
- boxes.each(&:display)
34
- # Boxes that leave the screen, we delete them note they have to be deleted
35
- # from both the box2d world and locally
36
- boxes.reject!(&:done)
34
+ boxes << Box.new(box2d, width / 2, 30) if rand < 0.99
35
+ boundaries.each(&:display)
36
+ boxes.each(&:display)
37
+ # Boxes that leave the screen, we delete them note they have to be deleted
38
+ # from both the box2d world and locally
39
+ boxes.reject!(&:done)
37
40
  exit if frame_count >= 908
38
41
  end
39
42
 
40
- class Boundary
41
- extend Forwardable
42
- def_delegators(:@app, :box2d, :fill, :rect, :rect_mode)
43
- # A boundary is a simple rectangle with x, y, width, and height
44
- attr_reader :x, :y, :w, :h, :b
45
-
46
- def initialize(app, x ,y, w, h)
47
- @app, @x ,@y, @w, @h = app, x ,y, w, h
48
- # Create the body
49
- bd = BodyDef.new
50
- bd.position.set(box2d.processing_to_world(x, y))
51
- @b = box2d.create_body(bd)
52
- # Figure out the box2d coordinates
53
- box2d_w = box2d.scale_to_world(w / 2)
54
- box2d_h = box2d.scale_to_world(h / 2)
55
- # Define the polygon
56
- sd = PolygonShape.new
57
- sd.setAsBox(box2d_w, box2d_h)
58
- fd = FixtureDef.new
59
- fd.shape = sd
60
- fd.density = 0
61
- fd.friction = 0.3
62
- fd.restitution = 0.5
63
- b.createFixture(fd)
64
- end
65
-
66
- # Draw the boundary, if it were at an angle we'd have to do something fancier
67
- def display
68
- fill(0)
69
- rect_mode(Java::ProcessingCore::PConstants::CENTER)
70
- rect(x, y, w, h)
71
- end
72
- end
73
-
74
43
  # A rectangular box
75
44
  class Box
76
- extend Forwardable
77
- def_delegators(:@app, :box2d, :rect_mode, :rect,
78
- :push_matrix, :pop_matrix, :fill, :rotate,
79
- :stroke, :stroke_weight, :translate)
45
+ include Processing::Proxy
80
46
  # We need to keep track of a Body and a width and height
81
- attr_reader :body, :w, :h
82
-
47
+ attr_reader :box2d, :body, :w, :h
48
+
83
49
  # Constructor
84
- def initialize(app, x, y)
50
+ def initialize(b2d, x, y)
85
51
  @w = rand(4..16)
86
52
  @h = rand(4..16)
87
- @app = app
53
+ @box2d = b2d
88
54
  # Add the box to the box2d world
89
55
  make_body(Vec2.new(x, y), w, h)
90
56
  end
91
-
57
+
92
58
  def done
93
59
  # Let's find the screen position of the particle
94
60
  pos = box2d.body_coord(body)
@@ -97,14 +63,14 @@ class Box
97
63
  box2d.destroy_body(body)
98
64
  true
99
65
  end
100
-
66
+
101
67
  # Drawing the box
102
68
  def display
103
69
  # We look at each body and get its screen position
104
70
  pos = box2d.body_coord(body)
105
71
  # Get its angle of rotation
106
- a = body.angle
107
- rect_mode(Java::ProcessingCore::PConstants::CENTER)
72
+ a = body.angle
73
+ rect_mode(CENTER)
108
74
  push_matrix
109
75
  translate(pos.x, pos.y)
110
76
  rotate(-a)
@@ -112,25 +78,25 @@ class Box
112
78
  rect(0, 0, w, h)
113
79
  pop_matrix
114
80
  end
115
-
81
+
116
82
  # This function adds the rectangle to the box2d world
117
- def make_body(center, w, h)
83
+ def make_body(center, w, h)
118
84
  # Define a polygon (this is what we use for a rectangle)
119
85
  sd = PolygonShape.new
120
86
  box2d_w = box2d.scale_to_world(w / 2)
121
87
  box2d_h = box2d.scale_to_world(h / 2)
122
- sd.setAsBox(box2d_w, box2d_h)
88
+ sd.setAsBox(box2d_w, box2d_h)
123
89
  # Define a fixture
124
90
  fd = FixtureDef.new
125
91
  fd.shape = sd
126
92
  # Parameters that affect physics
127
93
  fd.density = 1
128
94
  fd.friction = 0.3
129
- fd.restitution = 0.5
95
+ fd.restitution = 0.5
130
96
  # Define the body and make it from the shape
131
97
  bd = BodyDef.new
132
98
  bd.type = BodyType::DYNAMIC
133
- bd.position.set(box2d.processing_to_world(center))
99
+ bd.position.set(box2d.processing_to_world(center))
134
100
  cs = CircleShape.new
135
101
  @body = box2d.create_body(bd)
136
102
  body.create_fixture(fd)
@@ -139,3 +105,7 @@ class Box
139
105
  body.setAngularVelocity(rand(-5.0..5))
140
106
  end
141
107
  end
108
+
109
+ def settings
110
+ size(400,300)
111
+ end
@@ -10,8 +10,12 @@ require_relative 'particle_system'
10
10
 
11
11
  attr_reader :box2d, :windmill, :system
12
12
 
13
- def setup
13
+ def settings
14
14
  size(640,360)
15
+ end
16
+
17
+ def setup
18
+ sketch_title 'Revolute Joint'
15
19
  @box2d = Box2D.new(self)
16
20
  box2d.createWorld
17
21
  @windmill = Windmill.new(width / 2, 175)
@@ -0,0 +1,6 @@
1
+ ### Custom ContactListener example
2
+
3
+ This example is somewhat based on the CollisionListening example [Box2D for processing][] by Dan Shiffman, but with a CustomContact listener. It uses the jruby way of implementing an interface (which is to `include` it as if it were a `module`). Note the use of the more elegant ruby way to discriminate between Boundary (has no `:change` method) and Particle (`responds_to? :change` method) objects.
4
+
5
+ [Box2D for processing]:https://github.com/shiffman/Box2D-for-Processing
6
+
@@ -1,6 +1,6 @@
1
1
  require 'forwardable'
2
2
 
3
- CENTER ||= Java::ProcessingCore::PConstants::CENTER
3
+ CENTER ||= Java::ProcessingCore::CENTER
4
4
  # The boundary class is used to create a floor in this
5
5
  # sketch. Note it does not have a change method
6
6
  class Boundary
@@ -2,7 +2,7 @@
2
2
  # when two particles collide (no change just hitting boundary)
3
3
  class Particle
4
4
  extend Forwardable
5
- def_delegators(:@app, :box2d, :begin_shape, :color, :end_shape, :line, :pop_matrix,
5
+ def_delegators(:@app, :box2d, :begin_shape, :end_shape, :line, :pop_matrix,
6
6
  :ellipse, :translate, :rotate, :stroke, :push_matrix,
7
7
  :fill, :no_fill, :stroke_weight)
8
8
  attr_accessor :body
@@ -12,7 +12,7 @@ class Particle
12
12
  @app, @x, @y, @radius = app, x, y, r
13
13
  # This function puts the particle in the Box2d world
14
14
  make_body(x, y, radius)
15
- @col = color('#c0c0c0') # silver
15
+ @col = -5_263_441 # grey
16
16
  body.setUserData(self)
17
17
  end
18
18
 
@@ -23,7 +23,7 @@ class Particle
23
23
 
24
24
  # Change color when hit
25
25
  def change
26
- @col = color('#cc0000') # red
26
+ @col = -65_536 # red
27
27
  end
28
28
 
29
29
  # Is the particle ready for deletion?
@@ -16,7 +16,8 @@ def setup
16
16
  end
17
17
 
18
18
  def draw
19
- background(color('#ffffff'))
19
+ col = color('#ffffff')
20
+ background(col)
20
21
  particles << Particle.new(self, rand(width), 20, rand(4..8)) if rand < 0.1
21
22
  particles.each(&:display)
22
23
  particles.reject!(&:done)
data/lib/box2d.jar CHANGED
Binary file
data/lib/pbox2d/box2d.rb CHANGED
@@ -36,6 +36,6 @@ class Box2D < Java::ProcessingBox2d::Box2DProcessing
36
36
  end
37
37
 
38
38
  def version
39
- format('pbox2d version %s', Pbox2D::VERSION)
39
+ format('pbox2d version %s', Pbox2d::VERSION)
40
40
  end
41
41
  end
@@ -1,4 +1,3 @@
1
- # Module here just to keep namespace tidy
2
- module Pbox2D
3
- VERSION = '0.4.2'
1
+ module Pbox2d
2
+ VERSION = "0.5.0"
4
3
  end
data/pbox2d.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pbox2d/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'pbox2d'
8
+ spec.version = Pbox2d::VERSION
9
+ spec.license = 'FreeBSD/Simplified'
10
+ spec.has_rdoc = true
11
+ spec.extra_rdoc_files = ['README.md', 'LICENSE.md']
12
+ spec.authors = ['Martin Prout']
13
+ spec.email = ['martin_p@lineone.net']
14
+ spec.summary = %q{jbox2d wrapped in a gem for JRubyArt}
15
+ spec.description = <<-EOF
16
+ "An exemplar for how processing/java libraries can be made available for use
17
+ in JRubyArt. Features a maven build, also is an example of how to avoid an
18
+ overdose of java reflection by letting jruby sugar implement an interface"
19
+ EOF
20
+ spec.homepage = 'https://github.com/ruby-processing/jbox2d'
21
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ spec.files << 'lib/box2d.jar'
23
+ spec.files << 'lib/jbox2d-library-2.3.1-SNAPSHOT.jar'
24
+ spec.require_paths = ['lib']
25
+ spec.add_dependency 'jruby_art', '~> 1.0'
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "minitest", "~> 5.8"
28
+ spec.platform='java'
29
+ spec.requirements << 'A decent graphics card'
30
+ spec.requirements << 'java runtime >= 1.8+'
31
+ spec.requirements << 'processing = 3.0.1+'
32
+ spec.requirements << 'maven = 3.3.3'
33
+ end