(r, g, b, alpha=1.0)
return hue, sat, value, alpha
Converts a color given by its RGBA coordinates to HSVA coordinates
    (hue, saturation, value, alpha).

    Each of the RGBA coordinates must be in the range [0, 1].
Converts a color given by its RGBA coordinates to HSVA coordinates
    (hue, saturation, value, alpha).
Converts a color given by its RGBA coordinates to HSVA coordinates ( hue saturation value alpha ) .
def rgba_to_hsva(r, g, b, alpha=1.0):
    """Converts a color given by its RGBA coordinates to HSVA coordinates
    (hue, saturation, value, alpha).

    Each of the RGBA coordinates must be in the range [0, 1].
    """
    # This is based on the formulae found at:
    # http://en.literateprograms.org/RGB_to_HSV_color_space_conversion_(C)
    rgb_min, rgb_max = float(min(r, g, b)), float(max(r, g, b))
    alpha = float(alpha)
    value = float(rgb_max)
    if value <= 0:
        return 0.0, 0.0, 0.0, alpha
    sat = 1.0 - rgb_min / value
    if sat <= 0:
        return 0.0, 0.0, value, alpha
    d = rgb_max - rgb_min
    r = (r - rgb_min) / d
    g = (g - rgb_min) / d
    b = (b - rgb_min) / d
    rgb_max = max(r, g, b)
    if rgb_max == r:
        hue = 0.0 + (g - b) / 6.0
        if hue < 0:
            hue += 1
    elif rgb_max == g:
        hue = 1 / 3.0 + (b - r) / 6.0
    else:
        hue = 2 / 3.0 + (r - g) / 6.0
    return hue, sat, value, alpha
def rgba_to_hsva ( r , g , b , alpha = 1.0 ) : # This is based on the formulae found at: # http://en.literateprograms.org/RGB_to_HSV_color_space_conversion_(C) rgb_min , rgb_max = float ( min ( r , g , b ) ) , float ( max ( r , g , b ) ) alpha = float ( alpha ) value = float ( rgb_max ) if value <= 0 : return 0.0 , 0.0 , 0.0 , alpha sat = 1.0 - rgb_min / value if sat <= 0 : return 0.0 , 0.0 , value , alpha d = rgb_max - rgb_min r = ( r - rgb_min ) / d g = ( g - rgb_min ) / d b = ( b - rgb_min ) / d rgb_max = max ( r , g , b ) if rgb_max == r : hue = 0.0 + ( g - b ) / 6.0 if hue < 0 : hue += 1 elif rgb_max == g : hue = 1 / 3.0 + ( b - r ) / 6.0 else : hue = 2 / 3.0 + ( r - g ) / 6.0 return hue , sat , value , alpha