Skip to content

Color

The Color class represents a color value and related color helpers.

IMPORTANT

Static predefined colors such as Color.WHITE are shared instances. Clone them before mutating them. For example, use Color.WHITE.Clone().SetA(0) instead of changing Color.WHITE directly.


Properties

rnumber

The red component of the color.


gnumber

The green component of the color.


bnumber

The blue component of the color.


anumber

The alpha component of the color.


static readonly BLACKColor

Represents the predefined BLACK color value (0, 0, 0, 255).


static readonly REDColor

Represents the predefined RED color value (255, 0, 0, 255).


static readonly GREENColor

Represents the predefined GREEN color value (0, 255, 0, 255).


static readonly BLUEColor

Represents the predefined BLUE color value (0, 0, 255, 255).


static readonly YELLOWColor

Represents the predefined YELLOW color value (255, 255, 0, 255).


static readonly CYANColor

Represents the predefined CYAN color value (0, 255, 255, 255).


static readonly MAGENTAColor

Represents the predefined MAGENTA color value (255, 0, 255, 255).


static readonly WHITEColor

Represents the predefined WHITE color value (255, 255, 255, 255).


static readonly TRANSPARENTColor

Represents the predefined TRANSPARENT color value (0, 0, 0, 0).


Methods

constructor(r?: number, g?: number, b?: number, a?: number)

Creates a new Color instance.

  • rnumber (optional) - The red component of the color. Defaults to 255.
  • gnumber (optional) - The green component of the color. Defaults to 255.
  • bnumber (optional) - The blue component of the color. Defaults to 255.
  • anumber (optional) - The alpha component of the color. Defaults to 255.

static FromNumber(value: number)Color

Creates a new color from a number.

  • valuenumber - The number to create the color from.

Returned:


ToNumber()number

Converts the color to a number.

Returned:

  • number - The number representing the color.

SetRandom()this

Sets the color to a random color.

Returned:

  • this - This object.

SetR(value: number)this

Sets the red component of the color.

  • valuenumber - The value to use.

Returned:

  • this - The current instance for chaining.

SetG(value: number)this

Sets the green component of the color.

  • valuenumber - The value to use.

Returned:

  • this - The current instance for chaining.

SetB(value: number)this

Sets the blue component of the color.

  • valuenumber - The value to use.

Returned:

  • this - The current instance for chaining.

SetA(value: number)this

Sets the alpha component of the color.

  • valuenumber - The value to use.

Returned:

  • this - The current instance for chaining.

Clone()Color

Clones the color.

Returned:

  • Color - The cloned color.

ToVector()Vector

Converts the current value to a vector.

Returned:

  • Vector - The result of the call.