API

Class Color4

Class used to hold a RBGA color

Implements

  • Tensor<Tuple<number, 4>, IColor4Like>
Index
  • Creates a new Color4 object from red, green, blue values, all between 0 and 1

    Parameters

    • r: number = 0

      defines the red component (between 0 and 1, default is 0)

    • g: number = 0

      defines the green component (between 0 and 1, default is 0)

    • b: number = 0

      defines the blue component (between 0 and 1, default is 0)

    • a: number = 1

      defines the alpha component (between 0 and 1, default is 1)

    Returns Color4

a: number = 1

[1] Defines the alpha component (between 0 and 1, default is 1)

b: number = 0

[0] Defines the blue component (between 0 and 1, default is 0)

dimension: [4]

Tensor.dimension

g: number = 0

[0] Defines the green component (between 0 and 1, default is 0)

r: number = 0

[0] Defines the red component (between 0 and 1, default is 0)

rank: 1

Tensor.rank

_V8PerformanceHack: DeepImmutableObject<Color4> = ...

If the first color is flagged with integers (as everything is 0,0,0,0), V8 stores all of the properties as integers internally because it doesn't know any better yet. If subsequent colors are created with non-integer values, V8 determines that it would be best to represent these properties as doubles instead of integers, and henceforth it will use floating-point representation for all color instances that it creates. But the original color instances are unchanged and has a "deprecated map". If we keep using the color instances from step 1, it will now be a poison pill which will mess up optimizations in any code it touches.

  • Adds the given coordinates to the current Color4

    Parameters

    • r: number

      defines the r coordinate of the operand

    • g: number

      defines the g coordinate of the operand

    • b: number

      defines the b coordinate of the operand

    • a: number

      defines the a coordinate of the operand

    Returns this

    the current updated Color4

  • Updates the given color "result" with the result of the addition of the current Color4 and the given one.

    Type Parameters

    • T extends IColor4Like

    Parameters

    • otherColor: DeepImmutable<IColor4Like>

      the color to add

    • result: T

      the color to store the result

    Returns T

    result input

  • Creates a new array populated with 4 numeric elements : red, green, blue, alpha values

    Returns [number, number, number, number]

    the new array

  • Clamps the rgb values by the min and max values and stores the result into "result"

    Type Parameters

    • T extends IColor4Like

    Parameters

    • min: number = 0

      defines minimum clamping value (default is 0)

    • max: number = 1

      defines maximum clamping value (default is 1)

    • result: T

      defines color to store the result into.

    Returns T

    the result Color4

  • Copies the given float values into the current one

    Parameters

    • r: number

      defines the red component to read from

    • g: number

      defines the green component to read from

    • b: number

      defines the blue component to read from

    • a: number

      defines the alpha component to read from

    Returns this

    the current updated Color4 object

  • Boolean : True if the given floats are strictly equal to the current Color4 coordinates.

    Parameters

    • x: number

      x value to compare against

    • y: number

      y value to compare against

    • z: number

      z value to compare against

    • w: number

      w value to compare against

    Returns boolean

    true if equal

  • Boolean : True if the current Color4 coordinates are each beneath the distance "epsilon" from the given color ones.

    Parameters

    • otherColor: DeepImmutable<IColor4Like>

      color to compare against

    • epsilon: number = Epsilon

      (Default: very small number)

    Returns boolean

    true if they are equal

  • Update the current color with values stored in an array from the starting index of the given array

    Parameters

    • array: DeepImmutable<ArrayLike<number>>

      defines the source array

    • offset: number = 0

      defines an offset in the source array

    Returns this

    the current Color4 object

  • Updates the Color4 rgba values from the string containing valid hexadecimal values.

    A valid hex string is either in the format #RRGGBB or #RRGGBBAA.

    When a hex string without alpha is passed, the resulting Color4 keeps its previous alpha value.

    An invalid string does not modify this object

    Parameters

    • hex: string

      defines a string containing valid hexadecimal values

    Returns this

    the current updated Color4 object

  • Updates the current Color4 with the maximal coordinate values between its and the given coordinates.

    Parameters

    • r: number

      defines the r coordinate of the operand

    • g: number

      defines the g coordinate of the operand

    • b: number

      defines the b coordinate of the operand

    • a: number

      defines the a coordinate of the operand

    Returns this

    the current updated Color4

  • Updates the current Color4 with the minimal coordinate values between its and the given coordinates

    Parameters

    • r: number

      defines the r coordinate of the operand

    • g: number

      defines the g coordinate of the operand

    • b: number

      defines the b coordinate of the operand

    • a: number

      defines the a coordinate of the operand

    Returns this

    the current updated Color4

  • Returns a new Color4 set with the multiplication result of the given floats and the current Color4 coordinates.

    Parameters

    • r: number

      value multiply with

    • g: number

      value multiply with

    • b: number

      value multiply with

    • a: number

      value multiply with

    Returns Color4

    resulting new color

  • Multiply a Color4 value by another and push the result in a reference value

    Type Parameters

    • T extends IColor4Like

    Parameters

    • color: DeepImmutable<IColor4Like>

      defines the Color4 value to multiply by

    • result: T

      defines the Color4 to fill the result in

    Returns T

    the result Color4

  • Scale the current Color4 values by a factor and add the result to a given Color4

    Type Parameters

    • T extends IColor4Like

    Parameters

    • scale: number

      defines the scale factor

    • result: T

      defines the Color4 object where to store the result

    Returns T

    the result Color4

  • Multiplies the Color4 values by the float "scale"

    Parameters

    • scale: number

      defines the scaling factor to apply

    Returns this

    the current updated Color4

  • Multiplies the current Color4 values by scale and stores the result in "result"

    Type Parameters

    • T extends IColor4Like

    Parameters

    • scale: number

      defines the scaling factor to apply

    • result: T

      defines the Color4 object where to store the result

    Returns T

    the result Color4

  • Copies the given float values into the current one

    Parameters

    • r: number

      defines the red component to read from

    • g: number

      defines the green component to read from

    • b: number

      defines the blue component to read from

    • a: number

      defines the alpha component to read from

    Returns this

    the current updated Color4 object

  • Copies the given float to the current Vector4 coordinates

    Parameters

    • v: number

      defines the r, g, b, and a coordinates of the operand

    Returns this

    the current updated Vector4

  • Returns a new Color4 set with the result of the subtraction of the given floats from the current Color4 coordinates.

    Parameters

    • r: number

      value to subtract

    • g: number

      value to subtract

    • b: number

      value to subtract

    • a: number

      value to subtract

    Returns Color4

    new color containing the result

  • Sets the given color "result" set with the result of the subtraction of the given floats from the current Color4 coordinates.

    Type Parameters

    • T extends IColor4Like

    Parameters

    • r: number

      value to subtract

    • g: number

      value to subtract

    • b: number

      value to subtract

    • a: number

      value to subtract

    • result: T

      the color to store the result in

    Returns T

    result input

  • Subtracts the given ones from the current Color4 values and stores the results in "result"

    Type Parameters

    • T extends IColor4Like

    Parameters

    • otherColor: DeepImmutable<IColor4Like>

      defines the second operand

    • result: T

      defines the Color4 object where to store the result

    Returns T

    the result Color4 object

  • Stores from the starting index in the given array the Color4 successive values

    Parameters

    • array: FloatArray

      defines the array where to store the r,g,b components

    • index: number = 0

      defines an optional index in the target array to define where to start storing values

    Returns this

    the current Color4 object

  • Computes a new Color4 converted from the current one to gamma space

    Parameters

    • exact: boolean = false

      defines if the conversion will be done in an exact way which is slower but more accurate (default is false)

    Returns Color4

    a new Color4 object

  • Converts the Color4 values to gamma space and stores the result in "convertedColor"

    Parameters

    • convertedColor: IColor4Like

      defines the Color4 object where to store the gamma space version

    • exact: boolean = false

      defines if the conversion will be done in an exact way which is slower but more accurate (default is false)

    Returns this

    the unmodified Color4

  • Compute the Color4 hexadecimal code as a string

    Parameters

    • returnAsColor3: boolean = false

      defines if the string should only contains RGB values (off by default)

    Returns string

    a string containing the hexadecimal representation of the Color4 object

  • Computes a new Color4 converted from the current one to linear space

    Parameters

    • exact: boolean = false

      defines if the conversion will be done in an exact way which is slower but more accurate (default is false)

    Returns Color4

    a new Color4 object

  • Converts the Color4 values to linear space and stores the result in "convertedColor"

    Parameters

    • convertedColor: IColor4Like

      defines the Color4 object where to store the linear space version

    • exact: boolean = false

      defines if the conversion will be done in an exact way which is slower but more accurate (default is false)

    Returns this

    the unmodified Color4

  • Check the content of a given array and convert it to an array containing RGBA data If the original array was already containing count * 4 values then it is returned directly

    Parameters

    • colors: number[]

      defines the array to check

    • count: number

      defines the number of RGBA data to expect

    Returns number[]

    an array containing count * 4 values (RGBA)

  • Creates a new Color4 from the starting index element of the given array

    Parameters

    • array: DeepImmutable<ArrayLike<number>>

      defines the source array to read from

    • offset: number = 0

      defines the offset in the source array

    • result: Color4

      defines the target Color4 object

    Returns void

  • Creates a new Color4 from the string containing valid hexadecimal values.

    A valid hex string is either in the format #RRGGBB or #RRGGBBAA.

    When a hex string without alpha is passed, the resulting Color4 has its alpha value set to 1.0.

    An invalid string results in a Color with all its channels set to 0.0, i.e. "transparent black".

    Parameters

    • hex: string

      defines a string containing valid hexadecimal values

    Returns Color4

    a new Color4 object

  • Creates a new Color3 from integer values (less than 256)

    Parameters

    • r: number

      defines the red component to read from (value between 0 and 255)

    • g: number

      defines the green component to read from (value between 0 and 255)

    • b: number

      defines the blue component to read from (value between 0 and 255)

    • a: number

      defines the alpha component to read from (value between 0 and 255)

    Returns Color4

    a new Color3 object

  • Update a Color4 with the 1st derivative of the Hermite spline defined by the colors "value1", "value2", "tangent1", "tangent2".

    Parameters

    • value1: DeepImmutable<IColor4Like>

      defines the first control point

    • tangent1: DeepImmutable<IColor4Like>

      defines the first tangent

    • value2: DeepImmutable<IColor4Like>

      defines the second control point

    • tangent2: DeepImmutable<IColor4Like>

      defines the second tangent

    • time: number

      define where the derivative must be done

    • result: IColor4Like

      define where to store the derivative

    Returns void

  • Set the given "result" with the linearly interpolated values of "amount" between the left Color4 object and the right Color4 object

    Type Parameters

    • T extends IColor4Like

    Parameters

    • left: DeepImmutable<IColor4Like>

      defines the start value

    • right: DeepImmutable<IColor4Like>

      defines the end value

    • amount: number

      defines the gradient factor

    • result: T

      defines the Color4 object where to store data

    Returns T

    the updated result