Constructor
new Color(redopt, greenopt, blueopt, alphaopt)
Create a color with the components passed in, white by default
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
red | Number | <optional> | 1 | |
green | Number | <optional> | 1 | |
blue | Number | <optional> | 1 | |
alpha | Number | <optional> | 1 |
- Source
let a = new Color; // white
let b = new Color(1, 0, 0); // red
let c = new Color(0, 0, 0, 0); // transparent black
let d = RGB(0, 0, 1); // blue using rgb color
let e = HSL(.3, 1, .5); // green using hsl color
Members
a
PropertiesType | Description |
---|---|
Number | Alpha |
- Source
b
PropertiesType | Description |
---|---|
Number | Blue |
- Source
g
PropertiesType | Description |
---|---|
Number | Green |
- Source
r
PropertiesType | Description |
---|---|
Number | Red |
- Source
Methods
add(color) → {Color}
Returns a copy of this color plus the color passed in
Name | Type | Description |
---|---|---|
color | Color |
- Source
- Type:
- Color
clamp() → {Color}
Returns a copy of this color clamped to the valid range between 0 and 1
- Source
- Type:
- Color
copy() → {Color}
Returns a new color that is a copy of this
- Source
- Type:
- Color
divide(color) → {Color}
Returns a copy of this color divided by the color passed in
Name | Type | Description |
---|---|---|
color | Color |
- Source
- Type:
- Color
getHSLA() → {Array}
Returns this color expressed in hsla format
- Source
- Type:
- Array
lerp(color, percent) → {Color}
Returns a new color that is p percent between this and the color passed in
Name | Type | Description |
---|---|---|
color | Color | |
percent | Number |
- Source
- Type:
- Color
multiply(color) → {Color}
Returns a copy of this color times the color passed in
Name | Type | Description |
---|---|---|
color | Color |
- Source
- Type:
- Color
mutate(amountopt, alphaAmountopt) → {Color}
Returns a new color that has each component randomly adjusted
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
amount | Number | <optional> | .05 | |
alphaAmount | Number | <optional> | 0 |
- Source
- Type:
- Color
rgbaInt() → {Number}
Returns this color expressed as 32 bit RGBA value
- Source
- Type:
- Number
scale(scale, alphaScaleopt) → {Color}
Returns a copy of this color scaled by the value passed in, alpha can be scaled separately
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
scale | Number | |||
alphaScale | Number | <optional> | scale |
- Source
- Type:
- Color
setHSLA(hueopt, saturationopt, lightnessopt, alphaopt) → {Color}
Sets this color given a hue, saturation, lightness, and alpha
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
hue | Number | <optional> | 0 | |
saturation | Number | <optional> | 0 | |
lightness | Number | <optional> | 1 | |
alpha | Number | <optional> | 1 |
- Source
- Type:
- Color
setHex(hex) → {Color}
Set this color from a hex code
Name | Type | Description |
---|---|---|
hex | String | html hex code |
- Source
- Type:
- Color
subtract(color) → {Color}
Returns a copy of this color minus the color passed in
Name | Type | Description |
---|---|---|
color | Color |
- Source
- Type:
- Color
toString(useAlphaopt) → {String}
Returns this color expressed as a hex color code
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
useAlpha | Boolean | <optional> | 1 | if alpha should be included in result |
- Source
- Type:
- String