Skip to main content

Color

Defined in: src/lib/math.ts:569

Extends​

  • BaseVector<Color>

Constructors​

Constructor​

protected new Color(_array: Float32Array): Color;

Defined in: src/lib/math.ts:50

Parameters​

ParameterType
_arrayFloat32Array

Returns​

Color

Inherited from​

BaseVector\<Color\>.constructor

Properties​

PropertyModifierTypeDefault valueDescriptionInherited fromDefined in
_arrayprotectedFloat32Arrayundefined-BaseVector._arraysrc/lib/math.ts:50
_immutableprotectedbooleanfalse-BaseVector._immutablesrc/lib/math.ts:48
ONEreadonlyReadonly<Color>undefinedA color with all components set to 1. This is a truly immutable constant - any mutation attempt will throw an ImmutableVectorException. Clone before modifying.-src/lib/math.ts:582
ZEROreadonlyReadonly<Color>undefinedA color with all components set to 0. This is a truly immutable constant - any mutation attempt will throw an ImmutableVectorException. Clone before modifying.-src/lib/math.ts:575

Accessors​

a​

Get Signature​

get a(): number;

Defined in: src/lib/math.ts:643

The alpha component.

Returns​

number

Set Signature​

set a(value: number): void;

Defined in: src/lib/math.ts:649

Throws​

if this color is immutable.

Parameters​
ParameterType
valuenumber
Returns​

void


b​

Get Signature​

get b(): number;

Defined in: src/lib/math.ts:629

The blue component.

Returns​

number

Set Signature​

set b(value: number): void;

Defined in: src/lib/math.ts:635

Throws​

if this color is immutable.

Parameters​
ParameterType
valuenumber
Returns​

void


g​

Get Signature​

get g(): number;

Defined in: src/lib/math.ts:615

The green component.

Returns​

number

Set Signature​

set g(value: number): void;

Defined in: src/lib/math.ts:621

Throws​

if this color is immutable.

Parameters​
ParameterType
valuenumber
Returns​

void


immutable​

Get Signature​

get immutable(): boolean;

Defined in: src/lib/math.ts:55

Whether this vector is immutable.

Returns​

boolean

Inherited from​

BaseVector.immutable

int​

Get Signature​

get int(): number;

Defined in: src/lib/math.ts:659

Convert the color to a 32-bit integer.

Returns​

number

A 32-bit integer representing the color.


length​

Get Signature​

get length(): number;

Defined in: src/lib/math.ts:86

Returns​

number

Inherited from​

BaseVector.length

r​

Get Signature​

get r(): number;

Defined in: src/lib/math.ts:601

The red component.

Returns​

number

Set Signature​

set r(value: number): void;

Defined in: src/lib/math.ts:607

Throws​

if this color is immutable.

Parameters​
ParameterType
valuenumber
Returns​

void

Methods​

_createInstance()​

protected _createInstance(array: Float32Array\<ArrayBufferLike\> | number[]): Color;

Defined in: src/lib/math.ts:716

Parameters​

ParameterType
arrayFloat32Array<ArrayBufferLike> | number[]

Returns​

Color

Inherit Doc​

Overrides​

BaseVector._createInstance

_throwIfImmutable()​

protected _throwIfImmutable(operation: string): void;

Defined in: src/lib/math.ts:66

Throws an error if this vector is immutable.

Parameters​

ParameterTypeDescription
operationstringDescription of the attempted operation for the error message.

Returns​

void

Throws​

if this vector is immutable.

Inherited from​

BaseVector._throwIfImmutable

[iterator]()​

iterator: Generator<number, void, unknown>;

Defined in: src/lib/math.ts:354

Make this vector iterable for destructuring.

Returns​

Generator<number, void, unknown>

Inherited from​

BaseVector.[iterator]

add()​

add(other: Color): Color;

Defined in: src/lib/math.ts:136

Add another vector to this vector.

Parameters​

ParameterTypeDescription
otherColorThe vector to add to this vector.

Returns​

Color

A new vector with the result of the addition.

Throws​

if the index is out of bounds.

Inherited from​

BaseVector.add

at()​

at(index: number): number;

Defined in: src/lib/math.ts:98

Get the value at the given index.

Parameters​

ParameterTypeDescription
indexnumberThe index to get the value at.

Returns​

number

The value at the given index.

Throws​

if the index is out of bounds.

Inherited from​

BaseVector.at

clone()​

clone(): Color;

Defined in: src/lib/math.ts:317

Clone this vector.

Returns​

Color

A new vector with the same values.

Inherited from​

BaseVector.clone

distance()​

distance(other: Color): number;

Defined in: src/lib/math.ts:308

Calculate the distance between this vector and another vector.

Parameters​

ParameterTypeDescription
otherColorThe vector to calculate the distance to.

Returns​

number

The distance between this vector and the other vector.

Throws​

if the index is out of bounds.

Inherited from​

BaseVector.distance

div()​

div(other: Color): Color;

Defined in: src/lib/math.ts:203

Divide this vector by another vector.

Parameters​

ParameterTypeDescription
otherColorThe vector to divide this vector by.

Returns​

Color

A new vector with the result of the division.

Throws​

if the index is out of bounds.

Throws​

if the divisor is zero.

Inherited from​

BaseVector.div

dot()​

dot(other: Color): number;

Defined in: src/lib/math.ts:230

Calculate the dot product of this vector and another vector.

Parameters​

ParameterTypeDescription
otherColorThe vector to calculate the dot product with.

Returns​

number

The dot product of this vector and the other vector.

Throws​

if the index is out of bounds.

Inherited from​

BaseVector.dot

equals()​

equals(other: Color, epsilon: number): boolean;

Defined in: src/lib/math.ts:329

Check if this vector is equal to another vector. (Approximately)

Parameters​

ParameterTypeDefault valueDescription
otherColorundefinedThe vector to check equality with.
epsilonnumber1e-6The epsilon to use for the comparison.

Returns​

boolean

True if the vectors are equal, false otherwise.

Inherited from​

BaseVector.equals

freeze()​

freeze(): Readonly\<T\>;

Defined in: src/lib/math.ts:81

Mark this vector as immutable. Once frozen, any attempt to modify the vector will throw an ImmutableVectorException.

Note: The underlying Float32Array is not itself frozen; only this wrapper instance is. All mutation methods check the immutable flag and will throw.

Returns​

Readonly<T>

This vector, frozen and typed as Readonly<T>.

Inherited from​

BaseVector.freeze

magnitude()​

magnitude(): number;

Defined in: src/lib/math.ts:250

Calculate the magnitude of this vector.

Returns​

number

The magnitude of this vector.

Throws​

if the index is out of bounds.

Inherited from​

BaseVector.magnitude

mul()​

mul(other: Color): Color;

Defined in: src/lib/math.ts:180

Multiply this vector by another vector.

Parameters​

ParameterTypeDescription
otherColorThe vector to multiply this vector by.

Returns​

Color

A new vector with the result of the multiplication.

Throws​

if the index is out of bounds.

Inherited from​

BaseVector.mul

normalize()​

normalize(): Color;

Defined in: src/lib/math.ts:269

Normalize this vector.

Returns​

Color

A new vector with the result of the normalization.

Throws​

if the index is out of bounds.

Inherited from​

BaseVector.normalize

scale()​

scale(scalar: number): Color;

Defined in: src/lib/math.ts:287

Scale this vector by a scalar.

Parameters​

ParameterTypeDescription
scalarnumberThe scalar to scale this vector by.

Returns​

Color

A new vector with the result of the scaling.

Throws​

if the index is out of bounds.

Inherited from​

BaseVector.scale

setAt()​

setAt(index: number, value: number): void;

Defined in: src/lib/math.ts:116

Set the value at the given index.

Parameters​

ParameterTypeDescription
indexnumberThe index to set the value at.
valuenumberThe value to set at the given index.

Returns​

void

Throws​

if the index is out of bounds.

Throws​

if this vector is immutable.

Inherited from​

BaseVector.setAt

sub()​

sub(other: Color): Color;

Defined in: src/lib/math.ts:158

Subtract another vector from this vector.

Parameters​

ParameterTypeDescription
otherColorThe vector to subtract from this vector.

Returns​

Color

A new vector with the result of the subtraction.

Throws​

if the index is out of bounds.

Inherited from​

BaseVector.sub

toHex()​

toHex(): string;

Defined in: src/lib/math.ts:673

Convert the color to a hex string.

Returns​

string

A hex string representing the color.


create()​

static create(
   r: number, 
   g: number, 
   b: number, 
   a: number): Color;

Defined in: src/lib/math.ts:594

Create a color from individual components.

Parameters​

ParameterTypeDefault valueDescription
rnumberundefinedThe red component (0-1).
gnumberundefinedThe green component (0-1).
bnumberundefinedThe blue component (0-1).
anumber1The alpha component (0-1, default 1).

Returns​

Color

A new color.


fromHex()​

static fromHex(hex: string): Color;

Defined in: src/lib/math.ts:699

Create a color from a hex string.

Parameters​

ParameterTypeDescription
hexstringThe hex string to create the color from (e.g., "#ff0000" or "ff0000"). Supports 6 or 8 character hex strings (with optional alpha).

Returns​

Color

A new color.

Throws​

if the hex string is invalid.