lib/chunky_png/color.rb
# Returns an array with the separate HSV components of a color.
#
# Because ChunkyPNG internally handles colors as Integers for performance
# reasons, some rounding  occurs when importing or exporting HSV colors
# whose coordinates are float-based.  Because of this rounding, #to_hsv and
# #from_hsv may not be perfect inverses.
#
# This implementation follows the modern convention of 0 degrees hue
# indicating red.
#
# @param [Integer] color The ChunkyPNG color to convert.
# @param [Boolean] include_alpha Flag indicates whether a fourth element
#    representing alpha channel should be included in the returned array.
# @return [Array[0]] The hue of the color (0-360)
# @return [Array[1]] The saturation of the color (0-1)
# @return [Array[2]] The value of the color (0-1)
# @return [Array[3]] Optional fourth element for alpha, included if
#    include_alpha=true (0-255)
# @see https://en.wikipedia.org/wiki/HSL_and_HSV
Returns an array with the separate HSV components of a color.
Because ChunkyPNG internally handles colors as Integers for performance
reasons, some rounding  occurs when importing or exporting HSV colors
whose coordinates are float-based.  Because of this rounding, #to_hsv and
from_hsv may not be perfect inverses.

This implementation follows the modern convention of 0 degrees hue
indicating red.
Returns an array with the separate HSV components of a color . Because ChunkyPNG internally handles colors as Integers for performance reasons some rounding occurs when importing or exporting HSV colors whose coordinates are float - based . Because of this rounding #to_hsv and from_hsv may not be perfect inverses . This implementation follows the modern convention of 0 degrees hue indicating red .
def to_hsv(color, include_alpha = false)
      hue, chroma, max, _ = hue_and_chroma(color)
      value      = max
      saturation = chroma.zero? ? 0.0 : chroma.fdiv(value)
      include_alpha ? [hue, saturation, value, a(color)] :
                      [hue, saturation, value]
    end
def to_hsv ( color , include_alpha = false ) hue , chroma , max , _ = hue_and_chroma ( color ) value = max saturation = chroma . zero? ? 0.0 : chroma . fdiv ( value ) include_alpha ? [ hue , saturation , value , a ( color ) ] : [ hue , saturation , value ] end
Returns an array with the separate HSV components of a color.
Returns an array with the separate HSV components of a color .
] The hue of the color (0-360)
] The hue of the color ( 0 - 360 )
Array[0
] The saturation of the color (0-1)
] The saturation of the color ( 0 - 1 )
Array[1
] The value of the color (0-1)
] The value of the color ( 0 - 1 )
Array[2
] Optional fourth element for alpha, included if include_alpha=true (0-255)
] Optional fourth element for alpha included if include_alpha = true ( 0 - 255 )
Array[3
color
<not_specific>
include_alpha
<not_specific>
<not_specific>
include_alpha Flag indicates whether a fourth element representing alpha channel should be included in the returned array.
include_alpha Flag indicates whether a fourth element representing alpha channel should be included in the returned array .
see
None