Class Color4
Implements
- Tensor<Tuple<number, 4>, IColor4Like>
Index
Constructors
Properties
Methods
Constructors
constructor
-
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
- r: number = 0
Properties
a
[1] Defines the alpha component (between 0 and 1, default is 1)
b
[0] Defines the blue component (between 0 and 1, default is 0)
Readonlydimension
g
[0] Defines the green component (between 0 and 1, default is 0)
r
[0] Defines the red component (between 0 and 1, default is 0)
Readonlyrank
Static_ V8 Performance Hack
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.
Methods
add
-
Creates a new Color4 set with the added values of the current Color4 and of the given one
Parameters
- otherColor: DeepImmutable<IColor4Like>
defines the second operand
Returns Color4
a new Color4 object
- otherColor: DeepImmutable<IColor4Like>
add In Place
-
Adds in place the given Color4 values to the current Color4 object
Parameters
- otherColor: DeepImmutable<IColor4Like>
defines the second operand
Returns this
the current updated Color4 object
- otherColor: DeepImmutable<IColor4Like>
add In Place From Floats
-
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
- r: number
add To Ref
-
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
as Array
-
Creates a new array populated with 4 numeric elements : red, green, blue, alpha values
Returns [number, number, number, number]
the new array
clamp To Ref
-
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
clone
copy From
-
Copies the given Color4 values into the current one
Parameters
- source: DeepImmutable<IColor4Like>
defines the source Color4 object
Returns this
the current updated Color4 object
- source: DeepImmutable<IColor4Like>
copy From Floats
-
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
- r: number
equals
-
Determines equality between Color4 objects
Parameters
- otherColor: DeepImmutable<IColor4Like>
defines the second operand
Returns boolean
true if the rgba values are equal to the given ones
- otherColor: DeepImmutable<IColor4Like>
equals To Floats
-
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
- x: number
equals With Epsilon
-
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
- otherColor: DeepImmutable<IColor4Like>
from Array
-
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
- array: DeepImmutable<ArrayLike<number>>
from Hex String
-
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
- hex: string
get Class Name
-
Returns the string "Color4"
Returns string
"Color4"
get Hash Code
-
Compute the Color4 hash code
Returns number
an unique number that can be used to hash Color4 objects
maximize In Place
-
Updates the Color4 coordinates with the maximum values between its own and the given color ones
Parameters
- other: DeepImmutable<IColor4Like>
defines the second operand
Returns this
the current updated Color4
- other: DeepImmutable<IColor4Like>
maximize In Place From Floats
-
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
- r: number
minimize In Place
-
Updates the Color4 coordinates with the minimum values between its own and the given color ones
Parameters
- other: DeepImmutable<IColor4Like>
defines the second operand
Returns this
the current updated Color4
- other: DeepImmutable<IColor4Like>
minimize In Place From Floats
-
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
- r: number
multiply
-
Multiply an Color4 value by another and return a new Color4 object
Parameters
- color: DeepImmutable<IColor4Like>
defines the Color4 value to multiply by
Returns Color4
a new Color4 object
- color: DeepImmutable<IColor4Like>
multiply By Floats
-
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
- r: number
multiply In Place
-
Multiplies in place the current Color4 by the given one.
Parameters
- otherColor: DeepImmutable<IColor4Like>
color to multiple with
Returns this
the updated Color4.
- otherColor: DeepImmutable<IColor4Like>
multiply To Ref
-
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
-
Creates a new Color4 with the current Color4 values multiplied by scale
Parameters
- scale: number
defines the scaling factor to apply
Returns Color4
a new Color4 object
- scale: number
scale And Add To Ref
scale In Place
-
Multiplies the Color4 values by the float "scale"
Parameters
- scale: number
defines the scaling factor to apply
Returns this
the current updated Color4
- scale: number
scale To Ref
set
-
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
- r: number
set All
-
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
- v: number
subtract
-
Creates a new Color4 set with the subtracted values of the given one from the current Color4
Parameters
- otherColor: DeepImmutable<IColor4Like>
defines the second operand
Returns Color4
a new Color4 object
- otherColor: DeepImmutable<IColor4Like>
subtract From Floats
-
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
- r: number
subtract From Floats To Ref
-
subtractFromFloatsToRef<T extends IColor4Like>(
r: number,
g: number,
b: number,
a: number,
result: T,
): TSets 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
subtract In Place
-
Subtract in place the given color from the current Color4.
Parameters
- otherColor: DeepImmutable<IColor4Like>
the color to subtract
Returns this
the updated Color4.
- otherColor: DeepImmutable<IColor4Like>
subtract To Ref
-
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
to Array
-
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
- array: FloatArray
to Gamma Space
-
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
- exact: boolean = false
to Gamma Space To Ref
-
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
- convertedColor: IColor4Like
to Hex String
-
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
- returnAsColor3: boolean = false
to Linear Space
-
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
- exact: boolean = false
to Linear Space To Ref
-
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
- convertedColor: IColor4Like
to String
-
Creates a string with the Color4 current values
Returns string
the string representation of the Color4 object
StaticCheck Colors4
-
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)
- colors: number[]
StaticFrom Array
-
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
Returns Color4
a new Color4 object
- array: DeepImmutable<ArrayLike<number>>
StaticFrom Array To Ref
-
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
- array: DeepImmutable<ArrayLike<number>>
StaticFrom Color3
-
Creates a new Color4 from a Color3 and an alpha value
Parameters
- color3: DeepImmutable<IColor3Like>
defines the source Color3 to read from
- alpha: number = 1.0
defines the alpha component (1.0 by default)
Returns Color4
a new Color4 object
- color3: DeepImmutable<IColor3Like>
StaticFrom Hex String
-
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
- hex: string
StaticFrom Ints
-
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
- r: number
StaticHermite
-
Hermite(
value1: DeepImmutable<IColor4Like>,
tangent1: DeepImmutable<IColor4Like>,
value2: DeepImmutable<IColor4Like>,
tangent2: DeepImmutable<IColor4Like>,
amount: number,
): Color4Interpolate between two Color4 using Hermite interpolation
Parameters
- value1: DeepImmutable<IColor4Like>
defines first Color4
- tangent1: DeepImmutable<IColor4Like>
defines the incoming tangent
- value2: DeepImmutable<IColor4Like>
defines second Color4
- tangent2: DeepImmutable<IColor4Like>
defines the outgoing tangent
- amount: number
defines the target Color4
Returns Color4
the new interpolated Color4
- value1: DeepImmutable<IColor4Like>
StaticHermite1st Derivative
-
Hermite1stDerivative(
value1: DeepImmutable<IColor4Like>,
tangent1: DeepImmutable<IColor4Like>,
value2: DeepImmutable<IColor4Like>,
tangent2: DeepImmutable<IColor4Like>,
time: number,
): Color4Returns a new Color4 which is 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
Returns Color4
1st derivative
- value1: DeepImmutable<IColor4Like>
StaticHermite1st Derivative To Ref
-
Hermite1stDerivativeToRef(
value1: DeepImmutable<IColor4Like>,
tangent1: DeepImmutable<IColor4Like>,
value2: DeepImmutable<IColor4Like>,
tangent2: DeepImmutable<IColor4Like>,
time: number,
result: IColor4Like,
): voidUpdate 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
- value1: DeepImmutable<IColor4Like>
StaticLerp
-
Creates a new Color4 object set with the linearly interpolated values of "amount" between the left Color4 object and the right Color4 object
Parameters
- left: DeepImmutable<IColor4Like>
defines the start value
- right: DeepImmutable<IColor4Like>
defines the end value
- amount: number
defines the gradient factor
Returns Color4
a new Color4 object
- left: DeepImmutable<IColor4Like>
StaticLerp To Ref
-
LerpToRef<T extends IColor4Like>(
left: DeepImmutable<IColor4Like>,
right: DeepImmutable<IColor4Like>,
amount: number,
result: T,
): TSet 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
Class used to hold a RBGA color