examples/chipmunk_and_rmagick.rb
def create_boxes(num)
    box_vertices = polygon_vertices(NUM_SIDES, EDGE_SIZE)
    box_image = polygon_image(box_vertices)
    boxes =  []
    num.times do
      body = CP::Body.new(1, CP::moment_for_poly(1.0, box_vertices, CP::Vec2.new(0, 0))) # mass, moment of inertia
      body.p = CP::Vec2.new(rand(WIDTH), rand(40) - 50)
      shape = CP::Shape::Poly.new(body, box_vertices, CP::Vec2.new(0, 0))
      shape.e = 0.0
      shape.u = 0.4
      boxes << Box.new(box_image, body)
      @space.add_body(body)
      @space.add_shape(shape)      
    end
    return boxes
  end
# Produces the polygon objects and adds them to the space.
Produces the polygon objects and adds them to the space.
Produces the polygon objects and adds them to the space .
def create_boxes(num)
    box_vertices = polygon_vertices(NUM_SIDES, EDGE_SIZE)
    box_image = polygon_image(box_vertices)
    boxes =  []
    num.times do
      body = CP::Body.new(1, CP::moment_for_poly(1.0, box_vertices, CP::Vec2.new(0, 0))) 
      body.p = CP::Vec2.new(rand(WIDTH), rand(40) - 50)
      shape = CP::Shape::Poly.new(body, box_vertices, CP::Vec2.new(0, 0))
      shape.e = 0.0
      shape.u = 0.4
      boxes << Box.new(box_image, body)
      @space.add_body(body)
      @space.add_shape(shape)      
    end
    return boxes
  end
def create_boxes ( num ) box_vertices = polygon_vertices ( NUM_SIDES , EDGE_SIZE ) box_image = polygon_image ( box_vertices ) boxes = [ ] num . times do body = CP :: Body . new ( 1 , CP :: moment_for_poly ( 1.0 , box_vertices , CP :: Vec2 . new ( 0 , 0 ) ) ) body . p = CP :: Vec2 . new ( rand ( WIDTH ) , rand ( 40 ) - 50 ) shape = CP :: Shape :: Poly . new ( body , box_vertices , CP :: Vec2 . new ( 0 , 0 ) ) shape . e = 0.0 shape . u = 0.4 boxes << Box . new ( box_image , body ) @space . add_body ( body ) @space . add_shape ( shape ) end return boxes end
Produces the polygon objects and adds them to the space.
Produces the polygon objects and adds them to the space .
# mass, moment of inertia
num