rgb_to_lightness()

Converts an RGB color value to its corresponding lightness component in the HSL color space.

Syntax

lightness = rgb_to_lightness(color)

Parameters

Parameter Type Description Comment
color Number RGB color value in integer format (0xRRGGBB)

Return Value

Examples

Get the lightness of pure black (RGB: 0, 0, 0)

rgb_to_lightness(0x000000); // returns 0.0

Get the lightness of pure white (RGB: 255, 255, 255)

rgb_to_lightness(0xFFFFFF); // returns 100.0

Get the lightness of a medium gray (RGB: 128, 128, 128)

rgb_to_lightness(0x808080); // returns 50.1960814

Get the lightness of a light blue color (RGB: 173, 216, 230)

rgb_to_lightness(0xADD8E6); // returns 79.01960784

See also

rgb_to_hue
rgb_to_saturation
rgb_to_lightness
rgb_to_name

cam_color