Sha256: 1deda216c8f793906de17aed17a99bfd1449ae1f18922e30d03ad8b503091328

Contents?: true

Size: 1.19 KB

Versions: 3

Compression:

Stored size: 1.19 KB

Contents

# The Nature of Code
# <http:#www.shiffman.net/teaching/nature>
# Spring 2011
# PBox2D example

# Box2D particle system example

load_library :pbox2d
load_library :particle_system

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

attr_reader :box2d, :boundaries, :systems

def setup
  size(400,300)
  smooth  
  # Initialize box2d physics and create the world
  @box2d = PBox2D.new(self)
  box2d.create_world  
  # We are setting a custom gravity
  box2d.set_gravity(0, -20)  
  # Create ArrayLists	
  @systems = []
  @boundaries = []  
  # Add a bunch of fixed boundaries
  boundaries << Boundary.new(box2d, 50,100,300,5,-0.3)
  boundaries << Boundary.new(box2d, 250,175,300,5,0.5)  
end

def draw
  background(255)  
  # We must always step through time!
  box2d.step  
  # Run all the particle systems
  if systems.size > 0
    systems.each do |system|
      system.run 
      system.add_particles(box2d, rand(0 .. 2)) 
    end
  end  
  # Display all the boundaries
  boundaries.each do |wall|
    wall.display
  end
end


def mouse_pressed
  # Add a new Particle System whenever the mouse is clicked
  systems << ParticleSystem.new(box2d, 0, mouse_x, mouse_y)
end





Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ruby-processing-2.4.3 samples/external_library/java_processing/pbox2d/liquidy.rb~
ruby-processing-2.4.2 samples/external_library/java_processing/pbox2d/liquidy.rb~
ruby-processing-2.4.1 samples/external_library/java_processing/pbox2d/liquidy.rb~