Sha256: 3d6d4da2b58b0855989cd0b132ab852984bef44aa21b17aa975e89de937ab0ad
Contents?: true
Size: 1.03 KB
Versions: 2
Compression:
Stored size: 1.03 KB
Contents
# The Nature of Code # Daniel Shiffman # http://natureofcode.com # Example demonstrating revolute joint require 'pbox2d' require_relative 'windmill' require_relative 'particle' attr_reader :box2d, :windmill, :particles def setup size(640,360) @box2d = Box2D.new(self) box2d.createWorld @windmill = Windmill.new(width / 2, 175) @particles = [] end # Click the mouse to turn on or off the motor def mouse_pressed windmill.toggle_motor end def draw background(255) if rand < 0.1 sz = rand(4.0..8) particles << Particle.new(rand(width / 2 - 100..width / 2 + 100), -20, sz) end # Look at all particles, in reverse order particles.reverse_each do |p| p.display # Particles that leave the screen, we delete them # (note they have to be deleted from both the box2d world and our list next unless p.done? particles.shift end # Draw the windmill windmill.display status = windmill.motor_on? ? "ON" : "OFF" fill(0) text(format("Click mouse to toggle motor.\nMotor: %s", status), 10, height - 30) end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
pbox2d-0.4.1-java | examples/revolute_joint/revolute_joint.rb |
pbox2d-0.4.0-java | examples/revolute_joint/revolute_joint.rb |