Skip to main content

Class: Color

Class representing a color as 4 floating point values.

Constructors#

constructor#

new Color(r?, g?, b?, a?)

Creates a Color object with an RGBA structure.

Parameters#

NameTypeDefault valueDescription
rstring | number | Float32Array | ArrayBuffer0The red channel of a color.
gnumber0The green channel of a color.
bnumber0The blue channel of a color.
anumber1.0The alpha (transparency) channel of a color.

Defined in#

src/Math/Color.ts:16

Properties#

__data#

__data: Float32Array

Defined in#

src/Math/Color.ts:7

Accessors#

a#

get a(): number

Getter for alpha channel.

Returns#

number

  • Returns the alpha channel.

Defined in#

src/Math/Color.ts:99

set a(val): void

Setter for alpha value.

Parameters#

NameTypeDescription
valnumberThe val param.

Returns#

void

  • Returns the alpha channel.

Defined in#

src/Math/Color.ts:107


b#

get b(): number

Getter for blue channel.

Returns#

number

  • Returns the blue channel.

Defined in#

src/Math/Color.ts:81

set b(val): void

Setter for blue channel.

Parameters#

NameTypeDescription
valnumberThe val param.

Returns#

void

  • Returns the blue channel.

Defined in#

src/Math/Color.ts:90


g#

get g(): number

Getter for green channel.

Returns#

number

  • Returns the green channel.

Defined in#

src/Math/Color.ts:64

set g(val): void

Setter for green channel.

Parameters#

NameTypeDescription
valnumberThe val param.

Returns#

void

  • Returns the green channel.

Defined in#

src/Math/Color.ts:72


r#

get r(): number

Getter for red channel.

Returns#

number

  • Returns the red channel.

Defined in#

src/Math/Color.ts:46

set r(val): void

Setter for red channel.

Parameters#

NameTypeDescription
valnumberThe val param.

Returns#

void

  • Returns the red channel.

Defined in#

src/Math/Color.ts:55

Methods#

add#

add(other): Color

Returns a new Color which is this Color added to other.

Parameters#

NameTypeDescription
otherColorThe other color to add.

Returns#

Color

  • Returns a new color.

Defined in#

src/Math/Color.ts:455


addInPlace#

addInPlace(other): void

Updates this Color by adding the values from the other color.

Parameters#

NameTypeDescription
otherColorThe other color to add.

Returns#

void

Defined in#

src/Math/Color.ts:464


applyGamma#

applyGamma(gamma): void

Apply gamma correction to this color

Parameters#

NameTypeDescription
gammanumberThe gamma value.

Returns#

void

Defined in#

src/Math/Color.ts:508


approxEqual#

approxEqual(other, precision?): boolean

Returns true if this color is approximately the same as other.

Parameters#

NameTypeDefault valueDescription
otherColorundefinedThe other color to compare with.
precisionnumberNumber.EPSILONThe precision to which the values must match.

Returns#

boolean

  • Returns true or false.

Defined in#

src/Math/Color.ts:440


as3ComponentArray#

Private as3ComponentArray(): number[]

Returns the type as a 3 component array. Often used to pass types to the GPU.

Returns#

number[]

  • Returns as a 3 component array.

Defined in#

src/Math/Color.ts:614


asArray#

asArray(): Float32Array

Returns the type as an array. Often used to pass types to the GPU.

Returns#

Float32Array

  • Returns as an array.

Defined in#

src/Math/Color.ts:604


clone#

clone(): Color

Clones this color and returns a new color.

Returns#

Color

  • Returns a new color.

Defined in#

src/Math/Color.ts:595


fromJSON#

fromJSON(j): void

The fromJSON method decodes a json object for this type.

Parameters#

NameTypeDescription
jRecord<string, number>The json object.

Returns#

void

Defined in#

src/Math/Color.ts:640


getAsRGBArray#

getAsRGBArray(): number[]

Getter from an RGB array.

Returns#

number[]

  • The return value.

Defined in#

src/Math/Color.ts:155


getAsRGBDict#

getAsRGBDict(): Record<string, number>

Getter from an RGB dict.

Returns#

Record<string, number>

  • The return value.

Defined in#

src/Math/Color.ts:164


isEqual#

isEqual(other): boolean

Checks if this Color contains the same values as the other.

Parameters#

NameTypeDescription
otherColorThe other Color to compare with.

Returns#

boolean

  • Returns true if the values are the same, otherwise, false.

Defined in#

src/Math/Color.ts:419


lerp#

lerp(other, t): Color

Performs a linear interpolation between this color and other.

Parameters#

NameTypeDescription
otherColorThe other color to interpolate between.
tnumberInterpolation amount between the two inputs.

Returns#

Color

  • Returns a new color.

Defined in#

src/Math/Color.ts:553


luminance#

luminance(): number

Calculates and returns the luminance of the linear RGB components.

Returns#

number

  • The return value.

Defined in#

src/Math/Color.ts:542


notEquals#

notEquals(other): boolean

Returns true if this color is NOT exactly the same as other.

Parameters#

NameTypeDescription
otherColorThe other color to compare with.

Returns#

boolean

  • Returns true or false.

Defined in#

src/Math/Color.ts:429


readBinary#

readBinary(reader): void

Loads the state of the value from a binary reader.

Parameters#

NameTypeDescription
readerBinReaderThe reader value.

Returns#

void

Defined in#

src/Math/Color.ts:652


scale#

scale(scalar): Color

Scales this color by scalar and return the result as a new Vec4.

Parameters#

NameTypeDescription
scalarnumberThe scalar value.

Returns#

Color

  • Returns a new color.

Defined in#

src/Math/Color.ts:487


scaleInPlace#

scaleInPlace(scalar): void

Scales this color by scalar.

Parameters#

NameTypeDescription
scalarnumberThe scalar value.

Returns#

void

Defined in#

src/Math/Color.ts:496


set#

set(r, g, b, a?): void

Setter from scalar components.

Parameters#

NameTypeDefault valueDescription
rnumberundefinedThe red channel.
gnumberundefinedThe green channel.
bnumberundefinedThe blue channel.
anumber1.0The alpha channel.

Returns#

void

Defined in#

src/Math/Color.ts:119


setFromCSSColorName#

setFromCSSColorName(name): void

Sets the Color values from a CSS color name. E.g. "red"

Parameters#

NameTypeDescription
namestringThe CSS color name.

Returns#

void

Defined in#

src/Math/Color.ts:241


setFromHex#

setFromHex(hex): void

Setter from a hexadecimal value. E.g. #ff0000

Parameters#

NameTypeDescription
hexstringThe hex value.

Returns#

void

Defined in#

src/Math/Color.ts:216


setFromOther#

setFromOther(other): void

Sets current color state with another Color object.

Parameters#

NameTypeDescription
otherColorThe other color to set from.

Returns#

void

Defined in#

src/Math/Color.ts:131


setFromRGB#

setFromRGB(r, g, b, a?): void

Setter from a RGB value.

Parameters#

NameTypeDescription
rnumberThe red channel.
gnumberThe green channel.
bnumberThe blue channel.
a?numberThe alpha channel.

Returns#

void

Defined in#

src/Math/Color.ts:180


setFromRGBArray#

setFromRGBArray(vals): void

Setter from an RGB array.

Parameters#

NameTypeDescription
valsFloat32ArrayThe vals param.

Returns#

void

Defined in#

src/Math/Color.ts:192


setFromRGBDict#

setFromRGBDict(vals): void

Setter from an RGB dict.

Parameters#

NameTypeDescription
valsRecord<string, number>The vals param.

Returns#

void

Defined in#

src/Math/Color.ts:204


setFromScalarArray#

setFromScalarArray(vals): void

Setter from a scalar array.

Parameters#

NameTypeDescription
valsFloat32ArrayThe vals param.

Returns#

void

Defined in#

src/Math/Color.ts:143


subtract#

subtract(other): Color

Returns a new color which is this color subtracted from other.

Parameters#

NameTypeDescription
otherColorThe other color to subtract.

Returns#

Color

  • Returns a new color.

Defined in#

src/Math/Color.ts:477


toCSSString#

toCSSString(): string

Returns the CSS rgba string.

Returns#

string

  • The return value.

Defined in#

src/Math/Color.ts:664


toGamma#

toGamma(gamma?): Color

returns a new color value value is mapped into a gamma curve

Parameters#

NameTypeDefault valueDescription
gammanumber2.2The gamma value.

Returns#

Color

  • Returns a new color.

Defined in#

src/Math/Color.ts:528


toHex#

toHex(): string

Returns the hexadecimal value of this color, including the leading "#" character.

Returns#

string

  • Returns the hex value.

Defined in#

src/Math/Color.ts:404


toJSON#

toJSON(): Record<string, number>

The toJSON method encodes this type as a json object for persistence.

Returns#

Record<string, number>

  • The json object.

Defined in#

src/Math/Color.ts:626


toLinear#

toLinear(gamma?): Color

Converts to linear color space and returns a new color

Parameters#

NameTypeDefault valueDescription
gammanumber2.2The gamma value.

Returns#

Color

  • Returns a new color.

Defined in#

src/Math/Color.ts:518


random#

Static random(gammaOffset?, randomAlpha?): Color

Creates a random color.

Parameters#

NameTypeDefault valueDescription
gammaOffsetnumber0.0The gamma offset. Values between 0 and 1 increase the average brightness of the generated color. Values between 0 and -1 darken the generated color values.
randomAlphabooleanfalseDetermines whether the alpha channel is random. If not, the alpha values will be 1.0.

Returns#

Color

  • The new random color.

Defined in#

src/Math/Color.ts:568