Class: Ruby2D::Circle

Inherits:
Object
  • Object
show all
Includes:
Renderable
Defined in:
lib/ruby2d/circle.rb

Instance Attribute Summary collapse

Attributes included from Renderable

#color, #height, #width, #z

Class Method Summary collapse

Instance Method Summary collapse

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

#radiusObject

Returns the value of attribute radius.



7
8
9
# File 'lib/ruby2d/circle.rb', line 7

def radius
  @radius
end

#sectorsObject

Returns the value of attribute sectors.



7
8
9
# File 'lib/ruby2d/circle.rb', line 7

def sectors
  @sectors
end

#xObject

Returns the value of attribute x.



7
8
9
# File 'lib/ruby2d/circle.rb', line 7

def x
  @x
end

#yObject

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

Returns:

  • (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