Class: CP::Shape::Circle

Inherits:
Object
  • Object
show all
Defined in:
lib/chippunk.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, radius, center) ⇒ Circle

Returns a new instance of Circle.



49
50
51
52
# File 'lib/chippunk.rb', line 49

def initialize(body, radius, center)
  @radius, @center = radius, center
  orig_init(body,radius,center)
end

Instance Attribute Details

#centerObject (readonly)

Returns the value of attribute center.



46
47
48
# File 'lib/chippunk.rb', line 46

def center
  @center
end

#radiusObject (readonly)

Returns the value of attribute radius.



46
47
48
# File 'lib/chippunk.rb', line 46

def radius
  @radius
end

Instance Method Details

#draw(canvas) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/chippunk.rb', line 54

def draw(canvas)
  c = body.p + self.center.rotate(body.rot)
  a = body.a
  segs = 20
  coef = 2.0*Math::PI/(segs.to_f)
  
  points = Array.new(segs) do |n|
    rads = n*coef
    [radius*Math.cos(rads+a) + c.x, radius*Math.sin(rads + a) + c.y]
  end
  
  points.enum_cons(2) do |v1,v2|
    canvas.draw_line(v1[0], v1[1], Gosu::Color.new(0xffff0000), v2[0], v2[1], Gosu::Color.new(0xffff0000))
  end
end

#orig_initObject



47
# File 'lib/chippunk.rb', line 47

alias_method :orig_init, :initialize