Class SRGBColor

The SRGBColor implements a color in SRGB color space. The class follows the 'copy-on-write' pattern, which means that every operation such as SRGBColor.divideScalar or SRGBColor.multiply returns a copy of the color with updated values. It also implies that the values of the color cannot be directly modified.

The concept of immutability improves sharing of objects as all types in TypeScript are assigned by identity, instead of by-value (e.g. a copy) as in other programming languages like C.

Constructors

  • Parameters

    • Optionalr: number
    • Optionalg: number
    • Optionalb: number
    • Optionala: number

    Returns SRGBColor

Properties

_a: number
_b: number
_g: number
_r: number

Accessors

  • get a(): number
  • Returns number

  • set a(value): void
  • Parameters

    • value: number

    Returns void

  • get b(): number
  • Returns number

  • set b(value): void
  • Parameters

    • value: number

    Returns void

  • get g(): number
  • Returns number

  • set g(value): void
  • Parameters

    • value: number

    Returns void

  • get r(): number
  • Returns number

  • set r(value): void
  • Parameters

    • value: number

    Returns void

Methods

  • Copies all properties defined by the prototype of SRGBColor from other to this instance.

    Parameters

    Returns SRGBColor

  • Clones this instance and returns a new SRGBColor with identical values.

    Returns SRGBColor

  • Returns a copy of the current color divided by a factor.

    Parameters

    • factor: number

    Returns SRGBColor

  • Divides this color by a factor.

    Parameters

    • factor: number

    Returns SRGBColor

  • Performs scalar multiplication of this color and returns it.

    Parameters

    • factor: number
    • multiplyAlpha: boolean

    Returns SRGBColor

  • Accesses color components by an index.

    Parameters

    • index: number

      Index ranging [0, 3]

    Returns number

    Value of the component at the specified index.

  • Returns whether the provided color, given a error margin, has the same color components values as this one.

    Parameters

    • rhs: Immutable<SRGBColor>

      The other Color to compare with.

    • Optionalepsilon: number

      Optional. Error margin within which the numbers should be considered equal.

    Returns boolean

    True if equal, false otherwise.

  • Returns whether the given color contains the same color components values as this one.

    Parameters

    Returns boolean

  • Returns a copy of this color multiplied by the factor.

    Parameters

    • factor: number
    • multiplyAlpha: boolean

    Returns SRGBColor

  • Assigns the value to the element at the specified index.

    Parameters

    • index: number
    • value: number

    Returns void

  • Converts the current color to a Color.

    Returns Color

    No colorspace conversion is performed.

  • Converts the current color from SRGB to linear space and returns the result.

    Returns LinearColor

  • Returns a string representation of an object.

    Returns string

  • Converts this instance to a Vector3 with R/G/B while ignoring the alpha value.

    Returns Vector3

  • Compares two colors with an error margin.

    Parameters

    • lhs: Immutable<SRGBColor>

      First color to compare.

    • rhs: Immutable<SRGBColor>

      Second color to compare.

    • Optionalepsilon: number

      Optional. Error margin within which the numbers should be considered equal.

    Returns boolean

    True if equal, false otherwise.

  • Returns whether all the colors components contains the same values.

    Parameters

    Returns boolean