Class: Ruby2D::Rectangle
- Inherits:
-
Quad
- Object
- Quad
- Ruby2D::Rectangle
show all
- Defined in:
- lib/ruby2d/rectangle.rb
Direct Known Subclasses
Square
Instance Attribute Summary
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 Quad
#color=, #contains?
Methods included from Renderable
#add, #contains?, #remove
Constructor Details
#initialize(opts = {}) ⇒ Rectangle
Returns a new instance of Rectangle.
6
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/ruby2d/rectangle.rb', line 6
def initialize(opts = {})
@x = opts[:x] || 0
@y = opts[:y] || 0
@z = opts[:z] || 0
@width = opts[:width] || 200
@height = opts[:height] || 100
self.color = opts[:color] || 'white'
self.color.opacity = opts[:opacity] if opts[:opacity]
update_coords(@x, @y, @width, @height)
add
end
|
Class Method Details
.draw(opts = {}) ⇒ Object
42
43
44
45
46
47
48
49
|
# File 'lib/ruby2d/rectangle.rb', line 42
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[:width], opts[:y] , opts[:color][1][0], opts[:color][1][1], opts[:color][1][2], opts[:color][1][3],
opts[:x] + opts[:width], opts[:y] + opts[:height], opts[:color][2][0], opts[:color][2][1], opts[:color][2][2], opts[:color][2][3],
opts[:x] , opts[:y] + opts[:height], opts[:color][3][0], opts[:color][3][1], opts[:color][3][2], opts[:color][3][3]
])
end
|
Instance Method Details
#height=(h) ⇒ Object
37
38
39
40
|
# File 'lib/ruby2d/rectangle.rb', line 37
def height=(h)
@height = h
update_coords(@x, @y, @width, h)
end
|
#width=(w) ⇒ Object
32
33
34
35
|
# File 'lib/ruby2d/rectangle.rb', line 32
def width=(w)
@width = w
update_coords(@x, @y, w, @height)
end
|
#x=(x) ⇒ Object
18
19
20
21
22
23
|
# File 'lib/ruby2d/rectangle.rb', line 18
def x=(x)
@x = @x1 = x
@x2 = x + @width
@x3 = x + @width
@x4 = x
end
|
#y=(y) ⇒ Object
25
26
27
28
29
30
|
# File 'lib/ruby2d/rectangle.rb', line 25
def y=(y)
@y = @y1 = y
@y2 = y
@y3 = y + @height
@y4 = y + @height
end
|