- Color
Implement a color. All color components are expected to be in 0.0 - 1.0 range (and not 0-255).
- hexToColor(hex)
Convert Hex value to Color instance.
Implement a color. All color components are expected to be in 0.0 - 1.0 range (and not 0-255).
Kind: global class
- Color
- new Color(r, g, b, [a])
- instance
- .r ⇒
Number
- .g ⇒
Number
- .b ⇒
Number
- .a ⇒
Number
- .r ⇒
Number
- .g ⇒
Number
- .b ⇒
Number
- .a ⇒
Number
- .asHex ⇒
String
- .asDecimalRGBA ⇒
Number
- .asDecimalABGR ⇒
Number
- .floatArray
- .isBlack
- .isTransparentBlack
- .set(r, g, b, a) ⇒
Color
- .setByte(r, g, b, a) ⇒
Color
- .copy(other) ⇒
Color
- .toDict(minimized) ⇒
*
- .clone() ⇒
Number
- .string()
- .equals(other)
- .r ⇒
- static
- .webColorNames ⇒
Array.<String>
- .componentToHex(c) ⇒
String
- .fromHex(val) ⇒
Color
- .fromDecimal(val, includeAlpha) ⇒
Color
- .fromDict(data) ⇒
Color
- .random(includeAlpha) ⇒
Color
- .fromBytesArray(bytes, [offset]) ⇒
Color
- .lerp(p1, p2, a) ⇒
Color
- .webColorNames ⇒
Create the color.
Param | Type | Description |
---|---|---|
r | Number |
Color red component (value range: 0-1). |
g | Number |
Color green component (value range: 0-1). |
b | Number |
Color blue component (value range: 0-1). |
[a] | Number |
Color alpha component (value range: 0-1). |
Get r component.
Kind: instance property of Color
Returns: Number
- Red component.
Get g component.
Kind: instance property of Color
Returns: Number
- Green component.
Get b component.
Kind: instance property of Color
Returns: Number
- Blue component.
Get a component.
Kind: instance property of Color
Returns: Number
- Alpha component.
Set r component.
Kind: instance property of Color
Returns: Number
- Red component after change.
Set g component.
Kind: instance property of Color
Returns: Number
- Green component after change.
Set b component.
Kind: instance property of Color
Returns: Number
- Blue component after change.
Set a component.
Kind: instance property of Color
Returns: Number
- Alpha component after change.
Convert this color to hex string (starting with '#').
Kind: instance property of Color
Returns: String
- Color as hex.
Convert this color to decimal number.
Kind: instance property of Color
Returns: Number
- Color as decimal RGBA.
Convert this color to decimal number.
Kind: instance property of Color
Returns: Number
- Color as decimal ARGB.
Convert this color to a float array.
Kind: instance property of Color
Get if this color is pure black (ignoring alpha).
Kind: instance property of Color
Get if this color is transparent black.
Kind: instance property of Color
color.set(r, g, b, a) ⇒ Color
Set the color components.
Kind: instance method of Color
Returns: Color
- this.
Param | Type | Description |
---|---|---|
r | Number |
Color red component (value range: 0-1). |
g | Number |
Color green component (value range: 0-1). |
b | Number |
Color blue component (value range: 0-1). |
a | Number |
Color alpha component (value range: 0-1). |
color.setByte(r, g, b, a) ⇒ Color
Set the color components from byte values (0-255).
Kind: instance method of Color
Returns: Color
- this.
Param | Type | Description |
---|---|---|
r | Number |
Color red component (value range: 0-255). |
g | Number |
Color green component (value range: 0-255). |
b | Number |
Color blue component (value range: 0-255). |
a | Number |
Color alpha component (value range: 0-255). |
color.copy(other) ⇒ Color
Copy all component values from another color.
Kind: instance method of Color
Returns: Color
- this.
Param | Type | Description |
---|---|---|
other | Color |
Color to copy values from. |
Convert to dictionary.
Kind: instance method of Color
Returns: *
- Dictionary with {r,g,b,a}
Param | Type | Description |
---|---|---|
minimized | Boolean |
If true, will not include keys that their values are 1. You can use fromDict on minimized dicts. |
Return a clone of this color.
Kind: instance method of Color
Returns: Number
- Cloned color.
Convert to string.
Kind: instance method of Color
Check if equal to another color.
Kind: instance method of Color
Param | Type | Description |
---|---|---|
other | Color |
Other color to compare to. |
Get array with all built-in web color names.
Kind: static property of Color
Returns: Array.<String>
- Array with color names.
Convert a single component to hex value.
Kind: static method of Color
Returns: String
- Component as hex value.
Param | Type | Description |
---|---|---|
c | Number |
Value to convert to hex. |
Color.fromHex(val) ⇒ Color
Create color from hex value.
Kind: static method of Color
Returns: Color
- New color value.
Param | Type | Description |
---|---|---|
val | String |
Number value (hex), as #rrggbbaa. |
Color.fromDecimal(val, includeAlpha) ⇒ Color
Create color from decimal value.
Kind: static method of Color
Returns: Color
- New color value.
Param | Type | Description |
---|---|---|
val | Number |
Number value (int). |
includeAlpha | Number |
If true, will include alpha value. |
Color.fromDict(data) ⇒ Color
Create color from a dictionary.
Kind: static method of Color
Returns: Color
- Newly created color.
Param | Type | Description |
---|---|---|
data | * |
Dictionary with {r,g,b,a}. |
Color.random(includeAlpha) ⇒ Color
Return a random color.
Kind: static method of Color
Returns: Color
- Randomized color.
Param | Type | Description |
---|---|---|
includeAlpha | Boolean |
If true, will also randomize alpha. |
Color.fromBytesArray(bytes, [offset]) ⇒ Color
Build and return new color from bytes array.
Kind: static method of Color
Returns: Color
- Newly created color.
Param | Type | Description |
---|---|---|
bytes | Array.<Number> |
Bytes array to build color from. |
[offset] | Number |
Optional offset to read bytes from. |
Color.lerp(p1, p2, a) ⇒ Color
Lerp between two colors.
Kind: static method of Color
Returns: Color
- result color.
Param | Type | Description |
---|---|---|
p1 | Color |
First color. |
p2 | Color |
Second color. |
a | Number |
Lerp factor (0.0 - 1.0). |
Convert Hex value to Color instance.
Kind: global function
Param | Type | Description |
---|---|---|
hex | String |
Hex value to parse. |