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 |
- Source:
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 |
- Source:
# b
Properties
Type | Description |
---|---|
Number | Blue |
- Source:
# g
Properties
Type | Description |
---|---|
Number | Green |
- Source:
# r
Properties
Type | Description |
---|---|
Number | Red |
- Source:
Methods
# add(color) → {Color}
Returns a copy of this color plus the color passed in
Parameters:
Name | Type | Description |
---|---|---|
color |
Color |
- Source:
Returns:
- Type
- Color
# clamp() → {Color}
Returns a copy of this color clamped to the valid range between 0 and 1
- Source:
Returns:
- Type
- Color
# copy() → {Color}
Returns a new color that is a copy of this
- Source:
Returns:
- Type
- Color
# divide(color) → {Color}
Returns a copy of this color divided by the color passed in
Parameters:
Name | Type | Description |
---|---|---|
color |
Color |
- Source:
Returns:
- Type
- Color
# hex() → {String}
Returns this color expressed as a hex code
- Source:
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 |
- Source:
Returns:
- Type
- Color
# multiply(color) → {Color}
Returns a copy of this color times the color passed in
Parameters:
Name | Type | Description |
---|---|---|
color |
Color |
- Source:
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 |
- Source:
Returns:
- Type
- Color
# rgbaInt() → {Number}
Returns this color expressed as 32 bit integer RGBA value
- Source:
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 |
- Source:
Returns:
- Type
- Color
# setHex(hex) → {Color}
Set this color from a hex code
Parameters:
Name | Type | Description |
---|---|---|
hex |
String | html hex code |
- Source:
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 |
- Source:
Returns:
- Type
- Color
# subtract(color) → {Color}
Returns a copy of this color minus the color passed in
Parameters:
Name | Type | Description |
---|---|---|
color |
Color |
- Source:
Returns:
- Type
- Color
# toString() → {String}
Returns this color expressed as an CSS color value
- Source:
Returns:
- Type
- String