Color

Color

Color object (red, green, blue, alpha) with some helpful functions

Constructor

# new Color(redopt, greenopt, blueopt, alphaopt)

Create a color with the components passed in, white by default
Parameters:
Name Type Attributes Default Description
red Number <optional>
1
green Number <optional>
1
blue Number <optional>
1
alpha Number <optional>
1
Example
let a = new Color;             // white
let b = new Color(1, 0, 0);    // red
let c = new Color(0, 0, 0, 0); // transparent black

Members

# a

Properties
Type Description
Number Alpha

# b

Properties
Type Description
Number Blue

# g

Properties
Type Description
Number Green

# r

Properties
Type Description
Number Red

Methods

# add(color) → {Color}

Returns a copy of this color plus the color passed in
Parameters:
Name Type Description
color Color
Returns:
Type
Color

# clamp() → {Color}

Returns a copy of this color clamped to the valid range between 0 and 1
Returns:
Type
Color

# copy() → {Color}

Returns a new color that is a copy of this
Returns:
Type
Color

# divide(color) → {Color}

Returns a copy of this color divided by the color passed in
Parameters:
Name Type Description
color Color
Returns:
Type
Color

# hex() → {String}

Returns this color expressed as a hex code
Returns:
Type
String

# lerp(color, percent) → {Color}

Returns a new color that is p percent between this and the color passed in
Parameters:
Name Type Description
color Color
percent Number
Returns:
Type
Color

# multiply(color) → {Color}

Returns a copy of this color times the color passed in
Parameters:
Name Type Description
color Color
Returns:
Type
Color

# mutate(amountopt, alphaAmountopt) → {Color}

Returns a new color that has each component randomly adjusted
Parameters:
Name Type Attributes Default Description
amount Number <optional>
.05
alphaAmount Number <optional>
0
Returns:
Type
Color

# rgbaInt() → {Number}

Returns this color expressed as 32 bit integer RGBA value
Returns:
Type
Number

# scale(scale, alphaScaleopt) → {Color}

Returns a copy of this color scaled by the value passed in, alpha can be scaled separately
Parameters:
Name Type Attributes Default Description
scale Number
alphaScale Number <optional>
scale
Returns:
Type
Color

# setHex(hex) → {Color}

Set this color from a hex code
Parameters:
Name Type Description
hex String html hex code
Returns:
Type
Color

# setHSLA(hueopt, saturationopt, lightnessopt, alphaopt) → {Color}

Sets this color given a hue, saturation, lightness, and alpha
Parameters:
Name Type Attributes Default Description
hue Number <optional>
0
saturation Number <optional>
0
lightness Number <optional>
1
alpha Number <optional>
1
Returns:
Type
Color

# subtract(color) → {Color}

Returns a copy of this color minus the color passed in
Parameters:
Name Type Description
color Color
Returns:
Type
Color

# toString() → {String}

Returns this color expressed as an CSS color value
Returns:
Type
String