RGBAColor

color. RGBAColor

This class is used internally by the color module. It can be used to represent a color consisting of Red, Green, Blue and Alpha values. It also provides methods to mutate the color and methods to spawn new colors.

new RGBAColor(r, g, b, a)

Constructs a new RGBAColor instance with specified `r`, `g`, `b`, and `a` values.
Parameters:
Name Type Description
r Number Red (0..255)
g Number Green (0..255)
b Number Blue (0..255)
a Number Alpha (0..1)

Methods

clone(properties) → {RGBAColor}

Clones the color instance and optionally mutates properties
Parameters:
Name Type Argument Description
properties Object <optional>
hash-map of properties/vals to mutate once cloned. E.g. `{hue:.2, lightness:.3}`
Returns:
Cloned instance of color
Type
RGBAColor

darker(n)

Returns a darker color
Parameters:
Name Type Argument Description
n Number <optional>
Decreased by n lightness

get()

Get one of r, g, b, a, h, s, l

hsla() → {String}

Returns the color in hsla() format as specified in the CSS spec
Returns:
HSLA representation
Type
String

int32() → {Number}

Returns the color in 32-bit int repr
Returns:
Color as 32-bit int
Type
Number

lighter(n)

Returns a lighter color
Parameters:
Name Type Argument Description
n Number <optional>
Increase by n lightness

midpoint(c)

Returns the midpoint color between this color and whatever is passed
Parameters:
Name Type Description
c RGBAColor | String | Number The midpoint color

randomize(props, range) → {RGBAColor}

Returns a color with randomised properties as per the passed properties array and range.
Parameters:
Name Type Description
props Array | String The property/properties to be randomized
range Number The range of the randomisation. 0..1 for hsla, and 0..255 for rgba. If passed, then the randomization will occur around the current value to the specified degree. If no range is passed then the produced value could be anything (red = 0..255, alpha = 0..1 etc.)
Returns:
Randomly produced color
Type
RGBAColor

rgb() → {String}

Returns the color in rgb() format as specified in the CSS spec
Returns:
RGB representation
Type
String

rgba() → {String}

Returns the color in rgba() format as specified in the CSS spec
Returns:
RGBA representation
Type
String

set(prop, val)

Set one of r, g, b, a, h, s, l It allows the full forms too, since it only grabs charAt(0) E.g. red, alpha, hue, lightness etc.
Parameters:
Name Type Argument Description
prop String | Object Property to change (e.g. hue, or h) or a hash-map of properties andT values
val String <optional>
Value to change if prop is the property and NOT a hash-map

setColorMatrix(colorMatrix) → {RGBAColor}

Applies a colorMatrix
Parameters:
Name Type Description
colorMatrix colorMatrix The value of the colorMatrix filter
Returns:
The current RGBAColor instance
Type
RGBAColor

toString() → {String}

Returns the color in 32-bit repr ('0x')
Returns:
Color as '0x'
Type
String