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.<number>}
Returns this color expressed in hsla format
- Source
- Type:
- Array.<number>
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