Class: Ruby2D::Circle
- Inherits:
-
Object
- Object
- Ruby2D::Circle
- Includes:
- Renderable
- Defined in:
- lib/ruby2d/circle.rb
Instance Attribute Summary collapse
-
#radius ⇒ Object
Returns the value of attribute radius.
-
#sectors ⇒ Object
Returns the value of attribute sectors.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Attributes included from Renderable
Instance Method Summary collapse
- #contains?(x, y) ⇒ Boolean
-
#initialize(opts = {}) ⇒ Circle
constructor
A new instance of Circle.
Methods included from Renderable
#a, #a=, #add, #b, #b=, #colour, #colour=, #g, #g=, #opacity, #opacity=, #r, #r=, #remove
Constructor Details
#initialize(opts = {}) ⇒ Circle
Returns a new instance of Circle.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/ruby2d/circle.rb', line 9 def initialize(opts = {}) @x = opts[:x] || 25 @y = opts[:y] || 25 @z = opts[:z] || 0 @radius = opts[:radius] || 25 @sectors = opts[:sectors] || 20 self.color = opts[:color] || 'white' self.opacity = opts[:opacity] if opts[:opacity] add end |
Instance Attribute Details
#radius ⇒ Object
Returns the value of attribute radius.
7 8 9 |
# File 'lib/ruby2d/circle.rb', line 7 def radius @radius end |
#sectors ⇒ Object
Returns the value of attribute sectors.
7 8 9 |
# File 'lib/ruby2d/circle.rb', line 7 def sectors @sectors end |
#x ⇒ Object
Returns the value of attribute x.
7 8 9 |
# File 'lib/ruby2d/circle.rb', line 7 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
7 8 9 |
# File 'lib/ruby2d/circle.rb', line 7 def y @y end |
Instance Method Details
#contains?(x, y) ⇒ Boolean
20 21 22 |
# File 'lib/ruby2d/circle.rb', line 20 def contains?(x, y) Math.sqrt((x - @x)**2 + (y - @y)**2) <= @radius end |