Sha256: 539bc08130e3148249a3ae029b19cca1db1bb4ec108d0d699e9db3f84cff4777

Contents?: true

Size: 912 Bytes

Versions: 1

Compression:

Stored size: 912 Bytes

Contents

# The Nature of Code
# Daniel Shiffman
# http://natureofcode.com

# Example demonstrating distance joints
# A bridge is formed by connected a series of particles with joints

require 'pbox2d'
require 'forwardable'
require_relative 'boundary'
require_relative 'pair'
require_relative 'particle'
require_relative 'particle_system'

attr_reader :box2d, :boundaries, :system

def setup
  size(640, 360)
  # Initialize box2d physics and create the world
  @box2d = Box2D.new(self)
  box2d.create_world
  @system = ParticleSystem.new
  @boundaries = [
    Boundary.new(width / 4, height - 5, width / 2 - 50, 10),
    Boundary.new(3 * width / 4, height - 50, width / 2 - 50, 10)
  ]
end

def draw
  background(255)
  system.run
  # Display all the boundaries
  boundaries.each(&:display)
  fill(0)
  text('Click mouse to add connected particles.', 10, 20)
end

def mouse_pressed
  system.add_pair(mouse_x, mouse_y)
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pbox2d-0.4.2-java examples/distance_joint/distance_joint.rb