Color
Class representing a color.
Properties
r1
Red channel value between 0 and 1.
g1
Green channel value between 0 and 1.
b1
Blue channel value between 0 and 1.
is Color
Check the type whether it belongs to Color. This value should not be changed by user.
Methods
set RGB
Sets this color from RGB values.
Parameters
- r: number
Red channel value between 0.0 and 1.0.
- g: number
Green channel value between 0.0 and 1.0.
- b: number
Blue channel value between 0.0 and 1.0.
Returns Color
- r: number
copy
set Hex
Sets this color from a hexadecimal value.
Parameters
- hex: number
hexadecimal triplet format.
Returns Color
- hex: number
set HSL
Sets color from HSL values.
Parameters
- h: number
hue value between 0.0 and 1.0.
- s: number
saturation value between 0.0 and 1.0.
- l: number
lightness value between 0.0 and 1.0.
Returns Color
- h: number
set Style
Translucent colors such as "rgba(255, 0, 0, 0.5)" and "hsla(0, 100%, 50%, 0.5)" are also accepted, but the alpha-channel coordinate will be discarded.
Parameters
- style: string
color as a CSS-style string. Sets this color from a CSS-style string. For example, "rgb(250, 0,0)", "rgb(100%, 0%, 0%)", "hsl(0, 100%, 50%)", "#ff0000", "#f00", or "red" ( or any X11 color name
- all 140 color names are supported ).
- all 140 color names are supported ).
Returns Color
- style: string
set
set Scalar
Sets all three color components to the value Float| scalar.
Parameters
- scalar: number
a value between 0.0 and 1.0.
Returns Color
- scalar: number
clone
clone Readonly
- cloneReadonly(): Readonly<
Pick<
ReadonlyMarked,
| "_readonly_mark"
| "cloneReadonly"
| "clone"
| "g"
| "r"
| "b"
| "isColor"
| "equals"
| "getHex"
| "getSerializeData",
>,
>Returns Readonly<
Pick<
ReadonlyMarked,
| "_readonly_mark"
| "cloneReadonly"
| "clone"
| "g"
| "r"
| "b"
| "isColor"
| "equals"
| "getHex"
| "getSerializeData",
>,
>
copy Gamma To Linear2.0
copy Linear To Gamma2.0
convert Gamma To Linear2.0
Converts this color from gamma space to linear space by taking .r| r, .g| g and .b| b to the power of Float| gammaFactor.
Parameters
- gammaFactor: number
(optional).
Returns Color
- gammaFactor: number
convert Linear To Gamma2.0
Converts this color from linear space to gamma space by taking .r| r, .g| g and .b| b to the power of 1 / Float| gammaFactor.
Parameters
- gammaFactor: number
(optional).
Returns Color
- gammaFactor: number
copy SRGB To Linear
copy Linear To SRGB
convert SRGB To Linear
Converts this color from sRGB space to linear space.
Returns Color
convert Linear To SRGB
Converts this color from linear space to sRGB space.
Returns Color
get Hex
Returns the hexadecimal value of this color.
Returns number
get Hex String
Returns the hexadecimal value of this color as a string (for example, 'FFFFFF').
Returns string
get HSL
Convert this Color's .r| r, .g| g and .b| b values to HSL format and returns an object of the form:
{ h: 0, s: 0, l: 0 }Parameters
- target: HSL
the result will be copied into this Object. Adds h, s and l keys to the object (if not already present).
Returns HSL
- target: HSL
get Style
Returns the value of this color as a CSS style string. Example:
rgb(255,0,0).Returns string
add
add Colors
add Scalar
sub
multiply
multiply Scalar
lerp
Linearly interpolates this color's RGB values toward the RGB values of the passed argument. The alpha argument can be thought of as the ratio between the two colors, where 0.0 is this color and 1.0 is the first argument.
Parameters
- color: Color
color to converge on.
- alpha: number
interpolation factor in the closed interval [0, 1].
Returns Color
- color: Color
equals
from Array
Sets this color's components based on an array formatted like [ r, g, b ].
Parameters
- array: ArrayLike<number>
Array of floats in the form [ r, g, b ].
- offset: number
An optional offset into the array.
Returns Color
- array: ArrayLike<number>
get Number Count
r,g,b return 3
Returns number
to Array
Returns an array of the form [ r, g, b ].
Parameters
- array: number[]
An optional array to store the color to.
- offset: number
An optional offset into the array.
Returns number[]
- array: number[]
offset HSL
Adds the given h, s, and l to this color's values. Internally, this converts the color's r, g and b values to HSL, adds h,s,l, and then converts the color back to RGB.
Parameters
- h: number
- s: number
- l: number
Returns Color
lerp HSL
Linearly interpolates this color's HSL values toward the HSL values of the passed argument. It differs from the classic lerp by not interpolating straight from one color to the other, but instead going through all the hues in between those two colors. The alpha argument can be thought of as the ratio between the two colors, where 0.0 is this color and 1.0 is the first argument.
Parameters
- color: Color
- alpha: number
Returns this
Statichex2string
Converts a hexadecimal color number to a string.
Color.hex2string(0xffffff); -hex - Number in hex (e.g.,0xffffff) -return The string color (e.g.,"#ffffff").Parameters
- hex: number
Returns string
Statichex2rgb
- hex2rgb(
hex: number,
out?: number[] | Float32Array<ArrayBufferLike>,
): number[] | Float32Array<ArrayBufferLike>Converts a hexadecimal color number to an [R, G, B] array of normalized floats (numbers from 0.0 to 1.0).
Color.hex2rgb(0xffffff); // returns [1, 1, 1] -hex The hexadecimal number to convert -out If supplied, this array will be used rather than returning a new one -return An array representing the [R, G, B] of the color where all values are floats.Parameters
- hex: number
- out: number[] | Float32Array<ArrayBufferLike>
Returns number[] | Float32Array<ArrayBufferLike>
Staticrgb2hex
Converts a color as an [R, G, B] array to a hex number
Parameters
- rgb: number[] | Float32Array<ArrayBufferLike>
Returns number
Staticstring2hex
Converts a hexadecimal string to a hexadecimal color number.
Color.string2hex("#ffffff"); // returns 0xffffff -string - The string color (e.g.,"#ffffff") -return Number in hexadecimal.Parameters
- string: string
Returns number
Class representing a color.