Color
class Color
A color manipulation object.
Constructor
new Color(r: number, g: number, b: number, alpha: number) → {}
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
r | number |
<optional> |
0 |
red component [0 .. 255] |
g | number |
<optional> |
0 |
green component [0 .. 255] |
b | number |
<optional> |
0 |
blue component [0 .. 255] |
alpha | number |
<optional> |
1.0 |
alpha value [0.0 .. 1.0] |
Summary
Methods from Color
Public Properties
Public Methods
add(color: Color) → {Color}
Blend this color with the given one using addition.
Name | Type | Description |
---|---|---|
color | Color |
Type | Description |
---|---|
Color |
Reference to this object for method chaining |
clone() → {Color}
Create a new copy of this color object.
Type | Description |
---|---|
Color |
Reference to the newly cloned object |
copy(color: Color | string) → {Color}
Copy a color object or CSS color into this one.
Name | Type | Description |
---|---|---|
color | Color | string |
Type | Description |
---|---|
Color |
Reference to this object for method chaining |
darken(scale: number) → {Color}
Darken this color value by 0..1
Name | Type | Description |
---|---|---|
scale | number |
Type | Description |
---|---|
Color |
Reference to this object for method chaining |
equals(color: Color) → {boolean}
Return true if the r,g,b,a values of this color are equal with the given one.
Name | Type | Description |
---|---|---|
color | Color |
Type | Description |
---|---|
boolean |
lerp(color: Color, alpha: number) → {Color}
Linearly interpolate between this color and the given one.
Name | Type | Description |
---|---|---|
color | Color | |
alpha | number |
with alpha = 0 being this color, and alpha = 1 being the given one. |
Type | Description |
---|---|
Color |
Reference to this object for method chaining |
lighten(scale: number) → {Color}
Lighten this color value by 0..1
Name | Type | Description |
---|---|---|
scale | number |
Type | Description |
---|---|
Color |
Reference to this object for method chaining |
parseCSS(cssColor: string) → {Color}
Parse a CSS color string and set this color to the corresponding r,g,b values
Name | Type | Description |
---|---|---|
cssColor | string |
Type | Description |
---|---|
Color |
Reference to this object for method chaining |
parseHex(hexColor: string, argb : boolean) → {Color}
Parse a Hex color ("#RGB", "#RGBA" or "#RRGGBB", "#RRGGBBAA" format) and set this color to the corresponding r,g,b,a values
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
hexColor | string | |||
argb | boolean |
<optional> |
false |
true if format is #ARGB, or #AARRGGBB (as opposed to #RGBA or #RGGBBAA) |
Type | Description |
---|---|
Color |
Reference to this object for method chaining |
parseRGB(rgbColor: string) → {Color}
Parse an RGB or RGBA CSS color string
Name | Type | Description |
---|---|---|
rgbColor | string |
Type | Description |
---|---|
Color |
Reference to this object for method chaining |
random(min: number, max: number) → {Color}
Generate random r,g,b values for this color object
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
min | number |
<optional> |
0 |
minimum value for the random range |
max | number |
<optional> |
255 |
maxmium value for the random range |
Type | Description |
---|---|
Color |
Reference to this object for method chaining |
setColor(r: number, g: number, b: number, alpha: number) → {Color}
Set this color to the specified value.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
r | number |
red component [0 .. 255] |
||
g | number |
green component [0 .. 255] |
||
b | number |
blue component [0 .. 255] |
||
alpha | number |
<optional> |
1.0 |
alpha value [0.0 .. 1.0] |
Type | Description |
---|---|
Color |
Reference to this object for method chaining |
setFloat(r: number, g: number, b: number, alpha: number) → {Color}
set this color to the specified normalized float values
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
r | number |
red component [0.0 .. 1.0] |
||
g | number |
green component [0.0 .. 1.0] |
||
b | number |
blue component [0.0 .. 1.0] |
||
alpha | number |
<optional> |
1.0 |
alpha value [0.0 .. 1.0] |
Type | Description |
---|---|
Color |
Reference to this object for method chaining |
setHSL(h: number, s: number, l: number) → {Color}
set this color to the specified HSL value
Name | Type | Description |
---|---|---|
h | number |
hue (a value from 0 to 1) |
s | number |
saturation (a value from 0 to 1) |
l | number |
lightness (a value from 0 to 1) |
Type | Description |
---|---|
Color |
Reference to this object for method chaining |
setHSV(h: number, s: number, v: number) → {Color}
set this color to the specified HSV value
Name | Type | Description |
---|---|---|
h | number |
hue (a value from 0 to 1) |
s | number |
saturation (a value from 0 to 1) |
v | number |
value (a value from 0 to 1) |
Type | Description |
---|---|
Color |
Reference to this object for method chaining |
toArray() → {Float32Array}
return an Float Array representation of this object
Type | Description |
---|---|
Float32Array |
toHex() → {string}
return the color in "#RRGGBB" format
Type | Description |
---|---|
string |
toHex8(alpha) → {string}
Get the color in "#RRGGBBAA" format
Name | Type | Description |
---|---|---|
alpha |
Type | Description |
---|---|
string |
toRGB() → {string}
Get the color in "rgb(R,G,B)" format
Type | Description |
---|---|
string |
toRGBA(alpha: number) → {string}
Get the color in "rgba(R,G,B,A)" format
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
alpha | number |
<optional> |
1.0 |
alpha value [0.0 .. 1.0] |
Type | Description |
---|---|
string |
toUint32(alpha: number) → {number}
Pack this color RGB components into a Uint32 ARGB representation
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
alpha | number |
<optional> |
1.0 |
alpha value [0.0 .. 1.0] |
Type | Description |
---|---|
number |