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
Class Method Summary collapse
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=, #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] || 50 @sectors = opts[:sectors] || 30 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 |
Class Method Details
.draw(opts = {}) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/ruby2d/circle.rb', line 24 def self.draw(opts = {}) ext_draw([ opts[:x], opts[:y], opts[:radius], opts[:sectors], opts[:color][0], opts[:color][1], opts[:color][2], opts[:color][3] ]) 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 |