Color
Immutable RGBA color with components in [0, 1].
Color represents an RGBA value with four components. It is used for channel tints, label color maps, and wireframe overlays. Components are validated at construction and never change. Every API that takes a color accepts a ColorLike so hex strings and component arrays coerce automatically through from. Common colors are available as static presets.
Constructor
Creates a color from RGBA components in [0, 1].
new Color(r, g, b, a?): Color;| Parameter | Description |
|---|---|
r: number | The red component. |
g: number | The green component. |
b: number | The blue component. |
a?: number | The alpha component. Defaults to 1. |
Types
ColorLike
A value convertible to Color.
type ColorLike = Color | vec3 | vec4 | string;Properties
RED
Opaque red #ff0000.
readonly static RED: Color;GREEN
Opaque green #00ff00.
readonly static GREEN: Color;BLUE
Opaque blue #0000ff.
readonly static BLUE: Color;YELLOW
Opaque yellow #ffff00.
readonly static YELLOW: Color;MAGENTA
Opaque magenta #ff00ff.
readonly static MAGENTA: Color;CYAN
Opaque cyan #00ffff.
readonly static CYAN: Color;BLACK
Opaque black #000000.
readonly static BLACK: Color;WHITE
Opaque white #ffffff.
readonly static WHITE: Color;TRANSPARENT
Fully transparent black.
readonly static TRANSPARENT: Color;Accessors
rgb [number, number, number]
The RGB components as a three-element array.
get rgb(): [number, number, number];rgba readonly [number, number, number, number]
The RGBA components as a four-element array.
get rgba(): readonly [number, number, number, number];r number
The red component.
get r(): number;g number
The green component.
get g(): number;b number
The blue component.
get b(): number;a number
The alpha component.
get a(): number;rgbHex string
The color as a #rrggbb hex string. Alpha is dropped.
get rgbHex(): string;packed number
The color packed into a 32-bit integer as RGBA bytes.
get packed(): number;Methods
from() Color
Converts a ColorLike value to a Color.
static from(colorLike): Color;| Parameter | Description |
|---|---|
colorLike: ColorLike | The value to convert. |
fromRgbHex() Color
Parses a #rrggbb hex string into an opaque color.
static fromRgbHex(hex): Color;| Parameter | Description |
|---|---|
hex: string | The hex string with or without the leading #. |