Class: Ruby2D::Square

Inherits:
Rectangle show all
Defined in:
lib/ruby2d/square.rb

Instance Attribute Summary collapse

Attributes inherited from Quad

#c1, #c2, #c3, #c4, #x1, #x2, #x3, #x4, #y1, #y2, #y3, #y4

Attributes included from Renderable

#color, #height, #width, #x, #y, #z

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Rectangle

#height=, #width=, #x=, #y=

Methods inherited from Quad

#color=, #contains?

Methods included from Renderable

#add, #contains?, #remove

Constructor Details

#initialize(opts = {}) ⇒ Square

Returns a new instance of Square.



8
9
10
11
12
13
14
15
16
17
# File 'lib/ruby2d/square.rb', line 8

def initialize(opts = {})
  @x = opts[:x] || 0
  @y = opts[:y] || 0
  @z = opts[:z] || 0
  @width = @height = @size = opts[:size] || 100
  self.color = opts[:color] || 'white'
  self.color.opacity = opts[:opacity] if opts[:opacity]
  update_coords(@x, @y, @size, @size)
  add
end

Instance Attribute Details

#sizeObject

Returns the value of attribute size.



6
7
8
# File 'lib/ruby2d/square.rb', line 6

def size
  @size
end

Class Method Details

.draw(opts = {}) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/ruby2d/square.rb', line 24

def self.draw(opts = {})
  ext_draw([
    opts[:x]              , opts[:y]              , opts[:color][0][0], opts[:color][0][1], opts[:color][0][2], opts[:color][0][3],
    opts[:x] + opts[:size], opts[:y]              , opts[:color][1][0], opts[:color][1][1], opts[:color][1][2], opts[:color][1][3],
    opts[:x] + opts[:size], opts[:y] + opts[:size], opts[:color][2][0], opts[:color][2][1], opts[:color][2][2], opts[:color][2][3],
    opts[:x]              , opts[:y] + opts[:size], opts[:color][3][0], opts[:color][3][1], opts[:color][3][2], opts[:color][3][3]
  ])
end