Constructor
new Color(ropt, gopt, bopt, aopt)
Create a color with the rgba components passed in, white by default
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 |
- 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
HSLA() → {Array}
Returns this color expressed in hsla format
- Source
- Type:
- Array
add(c) → {Color}
Returns a copy of this color plus the color passed in
Name | Type | Description |
---|---|---|
c | Color | other 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(c) → {Color}
Returns a copy of this color divided by the color passed in
Name | Type | Description |
---|---|---|
c | Color | other color |
- Source
- Type:
- Color
isValid() → {Boolean}
Checks if this is a valid color
- Source
- Type:
- Boolean
lerp(c, percent) → {Color}
Returns a new color that is p percent between this and the color passed in
Name | Type | Description |
---|---|---|
c | Color | other color |
percent | Number |
- Source
- Type:
- Color
multiply(c) → {Color}
Returns a copy of this color times the color passed in
Name | Type | Description |
---|---|---|
c | Color | other 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> | 0.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
set(ropt, gopt, bopt, aopt) → {Color}
Sets values of this color and returns self
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 |
- Source
- Type:
- Color
setHSLA(hopt, sopt, lopt, aopt) → {Color}
Sets this color given a hue, saturation, lightness, and alpha
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
h | Number | <optional> | 0 | hue |
s | Number | <optional> | 0 | saturation |
l | Number | <optional> | 1 | lightness |
a | Number | <optional> | 1 | alpha |
- 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(c) → {Color}
Returns a copy of this color minus the color passed in
Name | Type | Description |
---|---|---|
c | Color | other color |
- Source
- Type:
- Color
toString(useAlphaopt) → {String}
Returns this color expressed as a hex color code
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
useAlpha | Boolean | <optional> | true | if alpha should be included in result |
- Source
- Type:
- String