Shaku

Shaku JS

Back To Table of Content

Color

Classes

Color

Implement a color. All color components are expected to be in 0.0 - 1.0 range (and not 0-255).

Functions

hexToColor(hex)

Convert Hex value to Color instance.

Color

Implement a color. All color components are expected to be in 0.0 - 1.0 range (and not 0-255).

Kind: global class

new Color(r, g, b, [a])

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).

color.r ⇒ Number

Get r component.

Kind: instance property of Color
Returns: Number - Red component.

color.g ⇒ Number

Get g component.

Kind: instance property of Color
Returns: Number - Green component.

color.b ⇒ Number

Get b component.

Kind: instance property of Color
Returns: Number - Blue component.

color.a ⇒ Number

Get a component.

Kind: instance property of Color
Returns: Number - Alpha component.

color.r ⇒ Number

Set r component.

Kind: instance property of Color
Returns: Number - Red component after change.

color.g ⇒ Number

Set g component.

Kind: instance property of Color
Returns: Number - Green component after change.

color.b ⇒ Number

Set b component.

Kind: instance property of Color
Returns: Number - Blue component after change.

color.a ⇒ Number

Set a component.

Kind: instance property of Color
Returns: Number - Alpha component after change.

color.asHex ⇒ String

Convert this color to hex string (starting with ‘#’).

Kind: instance property of Color
Returns: String - Color as hex.

color.asDecimalRGBA ⇒ Number

Convert this color to decimal number.

Kind: instance property of Color
Returns: Number - Color as decimal RGBA.

color.asDecimalABGR ⇒ Number

Convert this color to decimal number.

Kind: instance property of Color
Returns: Number - Color as decimal ARGB.

color.floatArray

Convert this color to a float array.

Kind: instance property of Color

color.isBlack

Get if this color is pure black (ignoring alpha).

Kind: instance property of Color

color.isTransparentBlack

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.

color.toDict(minimized) ⇒ \*

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.

color.clone() ⇒ Number

Return a clone of this color.

Kind: instance method of Color
Returns: Number - Cloned color.

color.string()

Convert to string.

Kind: instance method of Color

color.equals(other)

Check if equal to another color.

Kind: instance method of Color

Param Type Description
other Color Other color to compare to.

Color.webColorNames ⇒ Array.<String>

Get array with all built-in web color names.

Kind: static property of Color
Returns: Array.<String> - Array with color names.

Color.componentToHex(c) ⇒ String

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).

hexToColor(hex)

Convert Hex value to Color instance.

Kind: global function

Param Type Description
hex String Hex value to parse.