Skip to content

Commit

Permalink
update to shiffmans box2d library
Browse files Browse the repository at this point in the history
  • Loading branch information
monkstone committed Mar 2, 2014
1 parent a4de999 commit 0141974
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 658 deletions.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,7 +1,7 @@
syntax: glob
.DS_Store
*.sw*
*.*~
*~
*.pdf
*.gem
*.tgz
Expand Down
@@ -1,12 +1,11 @@
# The Nature of Code
# <http:#www.shiffman.net/teaching/nature>
# <http://www.shiffman.net/teaching/nature>
# Spring 2010
# PBox2D example

# An uneven surface

load_library :pbox2d
load_library :surface
load_libraries :box2d_processing, :surface

include SB

Expand All @@ -17,7 +16,7 @@ def setup
smooth

# Initialize box2d physics and create the world
@box2d = PBox2D.new(self)
@box2d = SB::Box2DProcessing.new(self)
box2d.create_world
# We are setting a custom gravity
box2d.set_gravity(0, -20)
Expand Down Expand Up @@ -46,11 +45,7 @@ def draw
end
# Particles that leave the screen, we delete them
# (note they have to be deleted from both the box2d world and our list
particles.each_with_index do |p, i|
if (p.done)
particles.delete_at(i)
end
end
particles.delete_if {|p| p.done}
# Just drawing the framerate to see how many particles it can handle
fill(0)
text("framerate: #{frame_rate.to_i}", 12, 16)
Expand Down
Expand Up @@ -3,7 +3,7 @@ module B2D
include_package 'org.jbox2d.collision.shapes'
include_package 'org.jbox2d.common'
include_package 'org.jbox2d.dynamics'
java_import 'pbox2d.PBox2D'
include_package 'shiffman.box2d'


# The Nature of Code
Expand Down
Expand Up @@ -2,22 +2,22 @@ module PS
include_package 'org.jbox2d.collision.shapes'
include_package 'org.jbox2d.common'
include_package 'org.jbox2d.dynamics'
java_import 'pbox2d.PBox2D'


include_package 'shiffman.box2d'

# Box2D Particle System
# <http://www.shiffman.net/teaching/nature>
# Spring 2010
# translated to ruby-processing Martin Prout

# A class to describe a group of Particles
# An ArrayList is used to manage the list of Particles
# An Array is used to manage the list of Particles

class ParticleSystem

attr_reader :particles, :x, :y

def initialize(bd, num, x, y)
@particles = [] # Initialize the ArrayList
@particles = [] # Initialize the Array
@x, @y = x, y # Store the origin point
num.times do
particles << PS::Particle.new(bd, x, y)
Expand All @@ -32,11 +32,8 @@ def run
# Particles that leave the screen, we delete them
# (note they have to be deleted from both the box2d world and our list

particles.each_with_index do |p, i|
if (p.done)
particles.delete_at(i)
end
end
particles.delete_if { |p| p.done}

end

def add_particles(bd, n)
Expand Down
@@ -1,5 +1,5 @@
# The Nature of Code
# <http:#www.shiffman.net/teaching/nature>
# <http://www.shiffman.net/teaching/nature>
# Spring 2010
# PBox2D example

Expand All @@ -9,7 +9,7 @@ module SB
include_package 'org.jbox2d.collision.shapes'
include_package 'org.jbox2d.common'
include_package 'org.jbox2d.dynamics'
java_import 'pbox2d.PBox2D'
include_package 'shiffman.box2d'



Expand Down
@@ -1,14 +1,14 @@
# The Nature of Code
# <http:#www.shiffman.net/teaching/nature>
# Spring 2011
# PBox2D example
# Updated to use the updated library
# translated to ruby-processing 2 March 2014 by Martin Prout
# Box2DProcessing example

# Box2D particle system example
load_libraries :box2d_processing, :particle_system

load_library :pbox2d
load_library :particle_system

# module PS is a wrapper for java imports, and Boundary and Particle classes
# module PS is a wrapper for java packages, and Boundary and Particle classes
include PS

attr_reader :box2d, :boundaries, :systems
Expand All @@ -17,11 +17,11 @@ def setup
size(400,300)
smooth
# Initialize box2d physics and create the world
@box2d = PBox2D.new(self)
@box2d = PS::Box2DProcessing.new(self)
box2d.create_world
# We are setting a custom gravity
box2d.set_gravity(0, -20)
# Create ArrayLists
# Create Arrays
@systems = []
@boundaries = []
# Add a bunch of fixed boundaries
Expand Down
@@ -1,11 +1,10 @@
# The Nature of Code
# <http://www.shiffman.net/teaching/nature>
# Spring 2011
# PBox2D example
# Box2DProcessing example

# Basic example of falling rectangles
load_library :pbox2d
load_library :custom_shape
load_libraries :box2d_processing, :custom_shape

# module B2D is a wrapper for java imports, and Boundary and CustomShape classes
include B2D
Expand All @@ -16,7 +15,7 @@ def setup
size(640,360)
smooth
# Initialize box2d physics and create the world
@box2d = PBox2D.new(self)
@box2d = B2D::Box2DProcessing.new(self)
box2d.create_world
# We are setting a custom gravity
box2d.set_gravity(0, -20)
Expand Down Expand Up @@ -46,11 +45,7 @@ def draw

# polygons that leave the screen, we delete them
# (note they have to be deleted from both the box2d world and our list
polygons.each_with_index do |polygon, i|
if polygon.done
polygons.delete_at(i)
end
end
polygons.delete_if { |p| p.done}
end

def mouse_pressed
Expand Down
32 changes: 0 additions & 32 deletions samples/external_library/java_processing/pbox2d/contact_test.rb~

This file was deleted.

This file was deleted.

0 comments on commit 0141974

Please sign in to comment.