Class: Color
Class representing a color as 4 floating point values.
#
Constructors#
constructor• new Color(r?
, g?
, b?
, a?
)
Creates a Color
object with an RGBA structure.
#
ParametersName | Type | Default value | Description |
---|---|---|---|
r | string | number | Float32Array | ArrayBuffer | 0 | The red channel of a color. |
g | number | 0 | The green channel of a color. |
b | number | 0 | The blue channel of a color. |
a | number | 1.0 | The alpha (transparency) channel of a color. |
#
Defined in#
Properties#
__data• __data: Float32Array
#
Defined in#
Accessors#
a• get
a(): number
Getter for alpha channel.
#
Returnsnumber
- Returns the alpha channel.
#
Defined in• set
a(val
): void
Setter for alpha value.
#
ParametersName | Type | Description |
---|---|---|
val | number | The val param. |
#
Returnsvoid
- Returns the alpha channel.
#
Defined in#
b• get
b(): number
Getter for blue channel.
#
Returnsnumber
- Returns the blue channel.
#
Defined in• set
b(val
): void
Setter for blue channel.
#
ParametersName | Type | Description |
---|---|---|
val | number | The val param. |
#
Returnsvoid
- Returns the blue channel.
#
Defined in#
g• get
g(): number
Getter for green channel.
#
Returnsnumber
- Returns the green channel.
#
Defined in• set
g(val
): void
Setter for green channel.
#
ParametersName | Type | Description |
---|---|---|
val | number | The val param. |
#
Returnsvoid
- Returns the green channel.
#
Defined in#
r• get
r(): number
Getter for red channel.
#
Returnsnumber
- Returns the red channel.
#
Defined in• set
r(val
): void
Setter for red channel.
#
ParametersName | Type | Description |
---|---|---|
val | number | The val param. |
#
Returnsvoid
- Returns the red channel.
#
Defined in#
Methods#
add▸ add(other
): Color
Returns a new Color which is this Color added to other.
#
ParametersName | Type | Description |
---|---|---|
other | Color | The other color to add. |
#
Returns- Returns a new color.
#
Defined in#
addInPlace▸ addInPlace(other
): void
Updates this Color by adding the values from the other color.
#
ParametersName | Type | Description |
---|---|---|
other | Color | The other color to add. |
#
Returnsvoid
#
Defined in#
applyGamma▸ applyGamma(gamma
): void
Apply gamma correction to this color
#
ParametersName | Type | Description |
---|---|---|
gamma | number | The gamma value. |
#
Returnsvoid
#
Defined in#
approxEqual▸ approxEqual(other
, precision?
): boolean
Returns true if this color is approximately the same as other.
#
ParametersName | Type | Default value | Description |
---|---|---|---|
other | Color | undefined | The other color to compare with. |
precision | number | Number.EPSILON | The precision to which the values must match. |
#
Returnsboolean
- Returns true or false.
#
Defined in#
as3ComponentArray▸ Private
as3ComponentArray(): number
[]
Returns the type as a 3 component array. Often used to pass types to the GPU.
#
Returnsnumber
[]
- Returns as a 3 component array.
#
Defined in#
asArray▸ asArray(): Float32Array
Returns the type as an array. Often used to pass types to the GPU.
#
ReturnsFloat32Array
- Returns as an array.
#
Defined in#
clone▸ clone(): Color
Clones this color and returns a new color.
#
Returns- Returns a new color.
#
Defined in#
fromJSON▸ fromJSON(j
): void
The fromJSON method decodes a json object for this type.
#
ParametersName | Type | Description |
---|---|---|
j | Record <string , number > | The json object. |
#
Returnsvoid
#
Defined in#
getAsRGBArray▸ getAsRGBArray(): number
[]
Getter from an RGB array.
#
Returnsnumber
[]
- The return value.
#
Defined in#
getAsRGBDict▸ getAsRGBDict(): Record
<string
, number
>
Getter from an RGB dict.
#
ReturnsRecord
<string
, number
>
- The return value.
#
Defined in#
isEqual▸ isEqual(other
): boolean
Checks if this Color contains the same values as the other.
#
ParametersName | Type | Description |
---|---|---|
other | Color | The other Color to compare with. |
#
Returnsboolean
- Returns
true
if the values are the same, otherwise,false
.
#
Defined in#
lerp▸ lerp(other
, t
): Color
Performs a linear interpolation between this color and other.
#
ParametersName | Type | Description |
---|---|---|
other | Color | The other color to interpolate between. |
t | number | Interpolation amount between the two inputs. |
#
Returns- Returns a new color.
#
Defined in#
luminance▸ luminance(): number
Calculates and returns the luminance of the linear RGB components.
#
Returnsnumber
- The return value.
#
Defined in#
notEquals▸ notEquals(other
): boolean
Returns true if this color is NOT exactly the same as other.
#
ParametersName | Type | Description |
---|---|---|
other | Color | The other color to compare with. |
#
Returnsboolean
- Returns true or false.
#
Defined in#
readBinary▸ readBinary(reader
): void
Loads the state of the value from a binary reader.
#
ParametersName | Type | Description |
---|---|---|
reader | BinReader | The reader value. |
#
Returnsvoid
#
Defined in#
scale▸ scale(scalar
): Color
Scales this color by scalar and return the result as a new Vec4.
#
ParametersName | Type | Description |
---|---|---|
scalar | number | The scalar value. |
#
Returns- Returns a new color.
#
Defined in#
scaleInPlace▸ scaleInPlace(scalar
): void
Scales this color by scalar.
#
ParametersName | Type | Description |
---|---|---|
scalar | number | The scalar value. |
#
Returnsvoid
#
Defined in#
set▸ set(r
, g
, b
, a?
): void
Setter from scalar components.
#
ParametersName | Type | Default value | Description |
---|---|---|---|
r | number | undefined | The red channel. |
g | number | undefined | The green channel. |
b | number | undefined | The blue channel. |
a | number | 1.0 | The alpha channel. |
#
Returnsvoid
#
Defined in#
setFromCSSColorName▸ setFromCSSColorName(name
): void
Sets the Color values from a CSS color name. E.g. "red"
#
ParametersName | Type | Description |
---|---|---|
name | string | The CSS color name. |
#
Returnsvoid
#
Defined in#
setFromHex▸ setFromHex(hex
): void
Setter from a hexadecimal value. E.g. #ff0000
#
ParametersName | Type | Description |
---|---|---|
hex | string | The hex value. |
#
Returnsvoid
#
Defined in#
setFromOther▸ setFromOther(other
): void
Sets current color state with another Color
object.
#
ParametersName | Type | Description |
---|---|---|
other | Color | The other color to set from. |
#
Returnsvoid
#
Defined in#
setFromRGB▸ setFromRGB(r
, g
, b
, a?
): void
Setter from a RGB value.
#
ParametersName | Type | Description |
---|---|---|
r | number | The red channel. |
g | number | The green channel. |
b | number | The blue channel. |
a? | number | The alpha channel. |
#
Returnsvoid
#
Defined in#
setFromRGBArray▸ setFromRGBArray(vals
): void
Setter from an RGB array.
#
ParametersName | Type | Description |
---|---|---|
vals | Float32Array | The vals param. |
#
Returnsvoid
#
Defined in#
setFromRGBDict▸ setFromRGBDict(vals
): void
Setter from an RGB dict.
#
ParametersName | Type | Description |
---|---|---|
vals | Record <string , number > | The vals param. |
#
Returnsvoid
#
Defined in#
setFromScalarArray▸ setFromScalarArray(vals
): void
Setter from a scalar array.
#
ParametersName | Type | Description |
---|---|---|
vals | Float32Array | The vals param. |
#
Returnsvoid
#
Defined in#
subtract▸ subtract(other
): Color
Returns a new color which is this color subtracted from other.
#
ParametersName | Type | Description |
---|---|---|
other | Color | The other color to subtract. |
#
Returns- Returns a new color.
#
Defined in#
toCSSString▸ toCSSString(): string
Returns the CSS rgba string.
#
Returnsstring
- The return value.
#
Defined in#
toGamma▸ toGamma(gamma?
): Color
returns a new color value value is mapped into a gamma curve
#
ParametersName | Type | Default value | Description |
---|---|---|---|
gamma | number | 2.2 | The gamma value. |
#
Returns- Returns a new color.
#
Defined in#
toHex▸ toHex(): string
Returns the hexadecimal value of this color, including the leading "#" character.
#
Returnsstring
- Returns the hex value.
#
Defined in#
toJSON▸ toJSON(): Record
<string
, number
>
The toJSON method encodes this type as a json object for persistence.
#
ReturnsRecord
<string
, number
>
- The json object.
#
Defined in#
toLinear▸ toLinear(gamma?
): Color
Converts to linear color space and returns a new color
#
ParametersName | Type | Default value | Description |
---|---|---|---|
gamma | number | 2.2 | The gamma value. |
#
Returns- Returns a new color.
#
Defined in#
random▸ Static
random(gammaOffset?
, randomAlpha?
): Color
Creates a random color.
#
ParametersName | Type | Default value | Description |
---|---|---|---|
gammaOffset | number | 0.0 | The gamma offset. Values between 0 and 1 increase the average brightness of the generated color. Values between 0 and -1 darken the generated color values. |
randomAlpha | boolean | false | Determines whether the alpha channel is random. If not, the alpha values will be 1.0. |
#
Returns- The new random color.