Class: Kracker::Zooka::Pixel
- Inherits:
-
Object
- Object
- Kracker::Zooka::Pixel
- Defined in:
- lib/kracker/zooka/pixel.rb
Instance Attribute Summary collapse
-
#alpha ⇒ Object
Returns the value of attribute alpha.
-
#blue ⇒ Object
Returns the value of attribute blue.
-
#green ⇒ Object
Returns the value of attribute green.
-
#red ⇒ Object
Returns the value of attribute red.
Instance Method Summary collapse
- #brightness ⇒ Object
- #hue ⇒ Object
-
#initialize(color_value) ⇒ Pixel
constructor
A new instance of Pixel.
Constructor Details
#initialize(color_value) ⇒ Pixel
Returns a new instance of Pixel.
6 7 8 9 10 11 |
# File 'lib/kracker/zooka/pixel.rb', line 6 def initialize(color_value) @alpha = ChunkyPNG::Color.a(color_value) @red = ChunkyPNG::Color.r(color_value) @green = ChunkyPNG::Color.g(color_value) @blue = ChunkyPNG::Color.b(color_value) end |
Instance Attribute Details
#alpha ⇒ Object
Returns the value of attribute alpha.
4 5 6 |
# File 'lib/kracker/zooka/pixel.rb', line 4 def alpha @alpha end |
#blue ⇒ Object
Returns the value of attribute blue.
4 5 6 |
# File 'lib/kracker/zooka/pixel.rb', line 4 def blue @blue end |
#green ⇒ Object
Returns the value of attribute green.
4 5 6 |
# File 'lib/kracker/zooka/pixel.rb', line 4 def green @green end |
#red ⇒ Object
Returns the value of attribute red.
4 5 6 |
# File 'lib/kracker/zooka/pixel.rb', line 4 def red @red end |
Instance Method Details
#brightness ⇒ Object
13 14 15 |
# File 'lib/kracker/zooka/pixel.rb', line 13 def brightness 0.3 * @red + 0.59 * @green + 0.11 * @blue end |
#hue ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/kracker/zooka/pixel.rb', line 17 def hue red = @red / 255.0 green = @green / 255.0 blue = @blue / 255.0 min = [red, green , blue].sort.first max = [red, green , blue].sort.last h = 0 d = 0 if max == min h = 0 else d = max - min h = case max when red (green - blue) / d + (green < blue ? 6 : 0) when green (blue - red) / d + 2 when blue (red - green ) / d + 4 else 0 end h = h / 6.0 end h end |