Sha256: 76b47fcc09cab5a332974b6bed82e8c9acf25e6b98b3e1ab55c3087a4d37175c
Contents?: true
Size: 999 Bytes
Versions: 1
Compression:
Stored size: 999 Bytes
Contents
# The Nature of Code # Daniel Shiffman # http://natureofcode.com # Basic example of falling rectangles require 'pbox2d' require_relative 'lib/boundary' require_relative 'lib/box' attr_reader :boxes, :boundaries, :box2d def setup size(640, 360, P2D) @box2d = Box2D.new(self) box2d.init_options(gravity: [0, -10]) box2d.create_world @boxes = [] box2d.world.set_particle_radius(0.15) box2d.world.set_particle_damping(0.2) @boundaries = [ Boundary.new(self, width / 4, height - 5, width / 2 - 50, 10), Boundary.new(self, 3 * width / 4, height - 50, width / 2 - 50, 10) ] end def mouse_pressed boxes << Box.new(box2d, mouse_x, mouse_y) end def draw background(255) boundaries.each(&:display) pos_buffer = box2d.world.particle_position_buffer return if pos_buffer.nil? stroke(0) stroke_weight(2) pos_buffer.each do |buf| pos = box2d.world_to_processing(buf) point(pos.x, pos.y) end fill(0) text(format('f.p.s %d', frame_rate.to_i), 10, 60) end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
pbox2d-0.4.2-java | examples/liquid_fun_test.rb |