Method: Rustle::Color#to_hsb
- Defined in:
- lib/rustle/color.rb
#to_hsb ⇒ Array<Fixnum>
Converts the Color object to an array of HSB values in the format [hue, saturation, brightness].
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/rustle/color.rb', line 159 def to_hsb r = @r / 255.0 g = @g / 255.0 b = @b / 255.0 max = [r, g, b].max min = [r, g, b].min delta = max - min hue = 0.0 brightness = max saturation = max == 0 ? 0 : (max - min) / max if delta != 0 if r == max hue = (g - b) / delta else if g == max hue = 2 + (b - r) / delta else hue = 4 + (r - g) / delta end end hue *= 60 hue += 360 if hue < 0 end [hue, saturation, brightness] end |