Color
A Color
object represents a color that can be displayed to the user.
The Color
class is not subclassable.
let color = new Color(ColorFormat.rgb, [1, 0, 0.5, 1]);
color.format == ColorFormat.rgb ==> true;
let red = color.components[0];
let green = color.components[1];
let blue = color.components[2];
let alpha = color.components[3];
Formats
Color objects may be constructed using several supported formats within the ColorFormat
enumeration, which correspond to both component representation and color space. Each format supports optionally specifying a final component which represents the alpha value of the color. If not specified, it is assumed the color has an alpha of 1.0 (100%).
Format | Description | Value |
---|---|---|
ColorFormat.rgb | sRGB color space, 3-component RGB format | “rgb” |
ColorFormat.hsl | sRGB color space, 3-component HSL format | “hsl” |
ColorFormat.hsb | sRGB color space, 3-component HSB format | “hsb” |
ColorFormat.displayP3 | Display P3 color space, 3-component RGB format | “p3” |
The ColorFormat enumeration was added in Nova 3. Previously, the raw values of this enumeration were used instead. If you are supporting previous versions, consider using the raw enumeration values listed above instead of the symbol.
Static Methods
rgb(red, green, blue, [alpha])
Creates a new color using the RGB format and sRGB color space, with an optional alpha value. If the alpha value is not specified, 1.0 will be used.
Added in Nova 3.
hsl(hue, saturation, luminance, [alpha])
Creates a new color using the HSL format and sRGB color space, with an optional alpha value. If the alpha value is not specified, 1.0 will be used.
Added in Nova 3.
hsb(hue, saturation, brightness, [alpha])
Creates a new color using the HSB format and sRGB color space, with an optional alpha value. If the alpha value is not specified, 1.0 will be used.
Added in Nova 3.
displayP3(red, green, blue, [alpha])
Creates a new color using the Display P3 format and color space, with an optional alpha value. If the alpha value is not specified, 1.0 will be used.
Added in Nova 3.
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.
Methods
convert(format)
Converts the receiver into a different color format, returning a new Color
object. The supported formats are the same as those listed in the table at the top of this document.