Class: CheekyPi::Color
- Inherits:
-
Struct
- Object
- Struct
- CheekyPi::Color
- Defined in:
- lib/cheeky-pi/color.rb
Instance Attribute Summary collapse
-
#b ⇒ Object
Returns the value of attribute b.
-
#g ⇒ Object
Returns the value of attribute g.
-
#r ⇒ Object
Returns the value of attribute r.
Class Method Summary collapse
-
.create(rgb) ⇒ Object
Create a new color from [r,g,b] array.
Instance Method Summary collapse
-
#blend(color, opacity) ⇒ Object
Blend with another color.
-
#darken(percent) ⇒ Object
Darken a color by a percent.
-
#distance(color) ⇒ Object
Returns color distance (maximum of rgb distances individually) from a target color.
-
#lighten(percent) ⇒ Object
Lighten color by percent.
Instance Attribute Details
#b ⇒ Object
Returns the value of attribute b
2 3 4 |
# File 'lib/cheeky-pi/color.rb', line 2 def b @b end |
#g ⇒ Object
Returns the value of attribute g
2 3 4 |
# File 'lib/cheeky-pi/color.rb', line 2 def g @g end |
#r ⇒ Object
Returns the value of attribute r
2 3 4 |
# File 'lib/cheeky-pi/color.rb', line 2 def r @r end |
Class Method Details
.create(rgb) ⇒ Object
Create a new color from [r,g,b] array
29 30 31 |
# File 'lib/cheeky-pi/color.rb', line 29 def self.create(rgb) new *rgb end |
Instance Method Details
#blend(color, opacity) ⇒ Object
Blend with another color
20 21 22 23 24 25 26 |
# File 'lib/cheeky-pi/color.rb', line 20 def blend(color, opacity) self.class.new( self.r * (1 - opacity) + color.r * opacity, self.g * (1 - opacity) + color.g * opacity, self.b * (1 - opacity) + color.b * opacity ) end |
#darken(percent) ⇒ Object
Darken a color by a percent
10 11 12 |
# File 'lib/cheeky-pi/color.rb', line 10 def darken(percent) blend(self.class.create(COLOR[:off]), percent) end |
#distance(color) ⇒ Object
Returns color distance (maximum of rgb distances individually) from a target color
15 16 17 |
# File 'lib/cheeky-pi/color.rb', line 15 def distance(color) [(self.r - color.r).abs, (self.g - color.g).abs, (self.b - color.b).abs].max end |
#lighten(percent) ⇒ Object
Lighten color by percent
5 6 7 |
# File 'lib/cheeky-pi/color.rb', line 5 def lighten(percent) blend(self.class.create(COLOR[:white]), percent) end |