Color

Color

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

Constructor

# new Color(ropt, gopt, bopt, aopt)

Create a color with the components passed in, white by default
Parameters:
Name Type Attributes Default Description
r Number <optional>
1 Red
g Number <optional>
1 Green
b Number <optional>
1 Blue
a Number <optional>
1 Alpha
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

# 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

# rgba() → {String}

Returns this color expressed as an rgba string
Returns:
Type
String

# rgbaInt() → {Number}

Returns this color expressed as 32 bit integer 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

# 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