Class: Ruby2D::Circle
- Inherits:
-
Object
- Object
- Ruby2D::Circle
- Includes:
- Renderable
- Defined in:
- lib/ruby2d/circle.rb
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
-
#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
10 11 12 13 14 15 16 17 18 |
# File 'lib/ruby2d/circle.rb', line 10 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' add end |
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
7 8 9 |
# File 'lib/ruby2d/circle.rb', line 7 def color @color end |
#radius ⇒ Object
Returns the value of attribute radius.
8 9 10 |
# File 'lib/ruby2d/circle.rb', line 8 def radius @radius end |
#sectors ⇒ Object
Returns the value of attribute sectors.
8 9 10 |
# File 'lib/ruby2d/circle.rb', line 8 def sectors @sectors end |
#x ⇒ Object
Returns the value of attribute x.
8 9 10 |
# File 'lib/ruby2d/circle.rb', line 8 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
8 9 10 |
# File 'lib/ruby2d/circle.rb', line 8 def y @y end |
Instance Method Details
#contains?(x, y) ⇒ Boolean
24 25 26 |
# File 'lib/ruby2d/circle.rb', line 24 def contains?(x, y) Math.sqrt((x - @x)**2 + (y - @y)**2) <= @radius end |