Class: Ruby2D::Circle
- Inherits:
-
Object
- Object
- Ruby2D::Circle
- Includes:
- Renderable
- Defined in:
- lib/ruby2d/circle.rb
Overview
Create a circle using Circle.new
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
Check if the circle contains the point at (x, y).
-
#initialize(x: 25, y: 25, z: 0, radius: 50, sectors: 30, color: nil, colour: nil, opacity: nil) ⇒ Circle
constructor
Create a circle.
Methods included from Renderable
Constructor Details
#initialize(x: 25, y: 25, z: 0, radius: 50, sectors: 30, color: nil, colour: nil, opacity: nil) ⇒ Circle
Create a circle
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ruby2d/circle.rb', line 23 def initialize(x: 25, y: 25, z: 0, radius: 50, sectors: 30, color: nil, colour: nil, opacity: nil) @x = x @y = y @z = z @radius = radius @sectors = sectors self.color = color || colour || 'white' self.color.opacity = opacity unless opacity.nil? add end |
Instance Attribute Details
#radius ⇒ Object
Returns the value of attribute radius.
12 13 14 |
# File 'lib/ruby2d/circle.rb', line 12 def radius @radius end |
#sectors ⇒ Object
Returns the value of attribute sectors.
12 13 14 |
# File 'lib/ruby2d/circle.rb', line 12 def sectors @sectors end |
#x ⇒ Object
Returns the value of attribute x.
12 13 14 |
# File 'lib/ruby2d/circle.rb', line 12 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
12 13 14 |
# File 'lib/ruby2d/circle.rb', line 12 def y @y end |
Class Method Details
.draw(opts = {}) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/ruby2d/circle.rb', line 40 def self.draw(opts = {}) Window.render_ready_check 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
Check if the circle contains the point at (x, y)
36 37 38 |
# File 'lib/ruby2d/circle.rb', line 36 def contains?(x, y) Math.sqrt((x - @x)**2 + (y - @y)**2) <= @radius end |