Color components are represented as numbers in the [0, 1] range.
new Color(
hexCode):Color
Creates a color from a hex code.
Supported formats are #RGB, #RGBA, #RRGGBB, and #RRGGBBAA. If parsing fails, the color remains in the state for which isNull returns true.
string
Hex color code.
Color
new Color(
r?,g?,b?,a?):Color
Creates a color from explicit component values.
Each provided component is clamped to the [0, 1] range. Components omitted during initialization, or explicitly passed as undefined, use default values: 0 for r, g, and b, and 1 for a. If all components are omitted, a color with unset components is created.
number
Red component.
number
Green component.
number
Blue component.
number
Alpha component.
Color
get a():
number
Returns the alpha component of the color.
number
set a(
a):void
Sets the alpha component of the color. The value is clamped to the [0, 1] range.
number
Alpha component.
void
Alpha component.
get b():
number
Returns the blue component of the color.
number
set b(
b):void
Sets the blue component of the color. The value is clamped to the [0, 1] range.
number
Blue component.
void
Blue component.
get g():
number
Returns the green component of the color.
number
set g(
g):void
Sets the green component of the color. The value is clamped to the [0, 1] range.
number
Green component.
void
Green component.
get r():
number
Returns the red component of the color.
number
set r(
r):void
Sets the red component of the color. The value is clamped to the [0, 1] range.
number
Red component.
void
Red component.
clone():
Color
Creates a new Color with the same component values as this color.
Color
copy(
other):this
Copies component values from another color.
Color
Other color.
this
staticfromRGB(rgb):Color
Creates a Color from an object implementing BaseRGB. The alpha component is initialized to 1.
Object implementing BaseRGB.
Color
staticfromRGB(rgb):Color
Creates a Color from a packed RGB integer in 0xRRGGBB format. The alpha component is initialized to 1.
number
Packed RGB value.
Color
staticfromRGBA(rgba):Color
Creates a Color from an object implementing BaseRGBA.
Object implementing BaseRGBA.
Color
staticfromRGBA(rgba):Color
Creates a Color from a packed RGBA integer in 0xRRGGBBAA format.
number
Packed RGBA value.
Color
getValue(
index):number
Returns a color component by index.
Component indices are 0 for red, 1 for green, 2 for blue, and 3 for alpha. Unset components are reported as 0. If index is outside the [0, 3] range, returns -1.
number
Component index.
number
isEqual(
other,tolerance?):boolean
Returns true if this color is equal to other within the specified tolerance.
Color
Other color.
number = Color.coincidenceTolerance
Per-component comparison tolerance. Defaults to 1e-4.
boolean
isNull():
boolean
Returns true if at least one component of the color is unset.
boolean
setA(
a):this
Sets the alpha component of the color. The value is clamped to the [0, 1] range.
number
Alpha component.
this
setB(
b):this
Sets the blue component of the color. The value is clamped to the [0, 1] range.
number
Blue component.
this
setG(
g):this
Sets the green component of the color. The value is clamped to the [0, 1] range.
number
Green component.
this
setR(
r):this
Sets the red component of the color. The value is clamped to the [0, 1] range.
number
Red component.
this
setValue(
index,value):this
Sets a color component by index.
Component indices are 0 for red, 1 for green, 2 for blue, and 3 for alpha. The value is clamped to the [0, 1] range. If index is outside the [0, 3] range, the call has no effect and the current object is returned unchanged.
number
Component index.
number
Component value.
this
setValues(
r?,g?,b?,a?):this
Sets the specified color components.
Each provided value is clamped to the [0, 1] range. Parameters that are undefined are not assigned explicitly. If a color with unset components is initialized by setting at least one component, the remaining unset components are initialized to their default values.
number
Red component.
number
Green component.
number
Blue component.
number
Alpha component.
this
toJSON():
BaseRGBA
Returns a JSON-serializable representation of the color.
toRGB():
number
Returns this color as a packed RGB integer in 0xRRGGBB format.
number
toRGBA():
number
Returns this color as a packed RGBA integer in 0xRRGGBBAA format.
number
toString():
string
Returns a string representation of the color.
string