Class: Rszr::Color::RGBA
- Inherits:
-
Base
- Object
- Base
- Rszr::Color::RGBA
show all
- Defined in:
- lib/rszr/color/rgba.rb
Instance Attribute Summary collapse
Attributes inherited from Base
#alpha
Instance Method Summary
collapse
Methods inherited from Base
#==, #cmya, #rgba, #to_fill
Constructor Details
#initialize(red, green, blue, alpha = 255) ⇒ RGBA
Returns a new instance of RGBA.
25
26
27
28
29
30
|
# File 'lib/rszr/color/rgba.rb', line 25
def initialize(red, green, blue, alpha = 255)
if red < 0 || red > 255 || green < 0 || green > 255 || blue < 0 || blue > 255 || alpha < 0 || alpha > 255
raise ArgumentError, 'color out of range'
end
@red, @green, @blue, @alpha = red, green, blue, alpha
end
|
Instance Attribute Details
#blue ⇒ Object
Returns the value of attribute blue.
23
24
25
|
# File 'lib/rszr/color/rgba.rb', line 23
def blue
@blue
end
|
#green ⇒ Object
Returns the value of attribute green.
23
24
25
|
# File 'lib/rszr/color/rgba.rb', line 23
def green
@green
end
|
#red ⇒ Object
Returns the value of attribute red.
23
24
25
|
# File 'lib/rszr/color/rgba.rb', line 23
def red
@red
end
|
Instance Method Details
#cyan ⇒ Object
32
33
34
|
# File 'lib/rszr/color/rgba.rb', line 32
def cyan
255 - red
end
|
#magenta ⇒ Object
36
37
38
|
# File 'lib/rszr/color/rgba.rb', line 36
def magenta
255 - green
end
|
#to_hex(alpha: true) ⇒ Object
49
50
51
|
# File 'lib/rszr/color/rgba.rb', line 49
def to_hex(alpha: true)
"#%0#{alpha ? 8 : 6}x" % to_i(alpha: alpha)
end
|
#to_i(alpha: true) ⇒ Object
44
45
46
47
|
# File 'lib/rszr/color/rgba.rb', line 44
def to_i(alpha: true)
i = red.to_i << 24 | green.to_i << 16 | blue.to_i << 8 | self.alpha.to_i
alpha ? i : i >> 8
end
|
#yellow ⇒ Object
40
41
42
|
# File 'lib/rszr/color/rgba.rb', line 40
def yellow
255 - blue
end
|