Sha256: f339369a67689afe95b6e279c0e255cee9169a2c7a09dfd5e1744edc7598e97b
Contents?: true
Size: 998 Bytes
Versions: 1
Compression:
Stored size: 998 Bytes
Contents
# Basic example of falling rectangles require 'pbox2d' require_relative 'lib/custom_shape' require_relative 'lib/boundary' require_relative 'lib/shape_system' attr_reader :box2d, :boundaries, :system Vect = Struct.new(:x, :y) def setup sketch_title 'Polygons' smooth @box2d = Box2D.new(self) box2d.init_options(gravity: [0, -20]) box2d.create_world @system = ShapeSystem.new self @boundaries = [ Boundary.new(box2d, Vect.new(width / 4, height - 5), Vect.new(width / 2 - 50, 10)), Boundary.new(box2d, Vect.new(3 * width / 4, height - 50), Vect.new(width / 2 - 50, 10)), Boundary.new(box2d, Vect.new(width - 5, height / 2), Vect.new(10, height)), Boundary.new(box2d, Vect.new(5, height / 2), Vect.new(10, height)) ] end def draw background(255) # Display all the boundaries boundaries.each(&:display) # Display all the polygons system.run end def mouse_pressed system << CustomShape.new(box2d, mouse_x, mouse_y) end def settings size(640, 360) end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
pbox2d-0.5.0-java | examples/polygons.rb |