Color

An Color object represents a color that can be displayed to the user.

The Color class is not subclassable.

let color = new Color("rgb", [1, 0, 0.5, 1]);

color.format == "rgb" ==> true;
let red = color.components[0];

Color objects may be specified in a number of supported formats, which correspond to both component representation and color space:

Format Description
rgb sRGB color space, 3-component RGB format with optional alpha
hsl sRGB color space, 3-component HSL format with optional alpha
hsb sRGB color space, 3-component HSB format with optional alpha
p3 Display P3 color space, 3-component RGB format with optional alpha

Class Methods

constructor(format, components)

Creates a new Color object in a supported format using the provided components. The components must be an array of numbers, and contain only as many components as required by the format chosen. Currently, all formats supported require at least 3 components, and most support up to 4 (three color values and an alpha value). An attempt to create a color object with the incorrect number of components will raise an Error. See the formats above for more information.

Properties

format

The format of the color, as a string.

This property is readonly.

components

The array of component numbers for the color.

This property is readonly.