some color generation functions
- Version
- 1.0
Methods
(static) HSBtoRGB(hue, sat, bri) → {Array}
Cover HSB color (0-1 range) to RGB color (0-255), this is based on the function in java.awt.Color
Name | Type | Description |
---|---|---|
hue | number | 0-1 |
sat | number | 0-1 |
bri | number | 0-1 |
int array representing the corresponding RGB color
- Type:
- Array
colorgen.HSBtoRGB(0.5,1,1);
// return [0, 255, 255];
(static) RGBtoHSB(red, green, blue) → {Array}
convert RGB (0-255) to HSB (0-1), base on the function in java.awt.Color
Name | Type | Description |
---|---|---|
red | number | between 0 - 255 |
green | number | between 0 - 255 |
blue | number | between 0 - 255 |
a float array representing the HSB color
- Type:
- Array
colorgen.RGBtoHSB(0, 255, 255);
//return [0.5, 1, 1]
(static) analogousColor(n, range, ref, sat, bri, offset1, offset2) → {Array}
Generate a bunch of color according to the analogous color scheme
Name | Type | Description |
---|---|---|
n | number | number of colors |
range | number | range of color |
ref | number | optional, reference angle, default is random |
sat | number | optional, float, 0 - 1, default to 1 |
bri | number | optional, float, 0 - 1, default to 1 |
offset1 | number | optional, float, offset amount 1, default 0, must between 0 - 1 |
offset2 | number | optional, float, offset amount 1, default 0, must between 0 - 1 |
- Tutorials
- See
- standerHarmonyColor
an array of colors in RGB format
- Type:
- Array
(static) colorDistance(color1, color2) → {number}
caculate the weighted Euclidean distance of two RGB colors
Name | Type | Description |
---|---|---|
color1 | * | a color, @seeparseColor for more info |
color2 | * | the other color, @seeparseColor for more info |
- Tutorials
the distance
- Type:
- number
(static) colorDistanceHSB(color1, color2) → {number}
caculate the unweighted Euclidean distance of two HSB colors in the HSB cone
Name | Type | Description |
---|---|---|
color1 | array | float array representing the first color, [H, S, B] range from 0 - 1; |
color2 | array | float array representing the second color, [H, S, B] range from 0 - 1; |
float, the distance between two color
- Type:
- number
(static) colorDistanceUnweightedRGB(color1, color2) → {number}
caculate the unweighted Euclidean distance of two RGB colors
Name | Type | Description |
---|---|---|
color1 | * | first color |
color2 | * | second color |
- See
- parseColor
float, the distance between two color
- Type:
- number
(static) complementaryColor(n, range1, range2, ref, sat, bri, offset2) → {Array}
Generate a bunch of color according to the complementary color scheme
Name | Type | Description |
---|---|---|
n | number | number of colors |
range1 | number | |
range2 | number | |
ref | number | optional, reference angle, default is random |
sat | number | optional, float, 0 - 1, default to 1 |
bri | number | optional, float, 0 - 1, default to 1 |
offset2 | number | optional, float, offset amount 2, default 0, must between 0 - 1 |
- Tutorials
- See
- standerHarmonyColor
an array of colors in RGB format
- Type:
- Array
(static) gradientRGB(n, from, to, type, sat, bri) → {Array}
generate a bunch of color in gradient, take different type
Name | Type | Description |
---|---|---|
n | number | the number of color return |
from | number | the starting point of the gradient (0 - 1) |
to | number | the end point of the gradient (0 - 1) |
type | string | how the colors are picked. "UR": Uniform Random, randomly select values between 0 and 1, and map this to the gradient to select colours. "G": Grid, uniform sections, no two colours will be closer to each other(along the gradient) than 1/n. "JG": Jittered Grid, grid with random offset. "GR" Golden Ratio, using golden ratio. |
sat | number | optional, satuation value between 0 - 1, defalut to 1 |
bri | number | optional, brightness value between 0 - 1, defalut to 1 |
- Tutorials
an array of rbg colors
- Type:
- Array
(static) parseColor(color) → {Array}
parse color input and output it as an array
Name | Type | Description |
---|---|---|
color | * | an array ([r,g,b]) or an object (o.r,o.g,o.b or o.R,o.G,o.B) or a (A)RGB color (only RGB is used in this library and only RGB is output from this function) |
an array representing the color [r,g,b];
- Type:
- Array
colorgen.parseColor({r:24, g:25, b:144});
//return [24,25,144]
(static) randomOffset(baseColor, offset) → {Array}
generate random offset color based on a chosen color
Name | Type | Description |
---|---|---|
baseColor | * | a color, @seeparseColor for more info |
offset | number | the max offset |
- Tutorials
an RGB array (range from 0 - 255);
- Type:
- Array
(static) randomRGB() → {Array}
get a random RGB color
- Tutorials
an array of int [R, G, B] in range of 0 - 255
- Type:
- Array
(static) splitcomplementaryColor(n, range1, range2, range3, vari, ref, sat, bri) → {Array}
Generate a bunch of color according to the split complementary color scheme
Name | Type | Description |
---|---|---|
n | number | number of colors |
range1 | number | |
range2 | number | range2, must smaller than 2*var |
range3 | number | range3, must smaller than 2*var |
vari | number | variation from 180 for the offset values |
ref | number | optional, reference angle, default is random |
sat | number | optional, float, 0 - 1, default to 1 |
bri | number | optional, float, 0 - 1, default to 1 |
- Tutorials
- See
- standerHarmonyColor
an array of colors in RGB format
- Type:
- Array
(static) standerHarmonyColor(n, range1, range2, range3, reference, sat, bri, offset1, offset2) → {Array}
Generate a bunch of color according to the stander harmony color scheme, see http://doi.acm.org/10.1145/1179352.1141933
Name | Type | Description |
---|---|---|
n | number | number of the colors |
range1 | number | float, range angle 1 in the hue ring |
range2 | number | float, range angle 2 in the hue ring |
range3 | number | float, range angle 3 in the hue ring |
reference | number | optional, float, as the reference hue for generation, default is random |
sat | number | optional, float (0 - 1), sat value, default to 1 |
bri | number | optional, float (0 - 1), bri value, default to 1 |
offset1 | number | optional, float, offset amount 1, default 0, must between 0 - 1 |
offset2 | number | optional, float, offset amount 2, default 0, must between 0 - 1 |
- See
- analogousColor complementaryColor splitcomplementaryColor triadColor
an array of color in RGB format
- Type:
- Array
(static) to24BitRGB(color) → {color}
cast the color to 24 bit int RGB color
Name | Type | Description |
---|---|---|
color | any | the color to cast, |
- See
- parseColor for input options
a 24bit int color
- Type:
- color
colorgen.to24BitRGB([255, 255, 255]).toString(16);
//return "ffffff"
(static) to32BitARGB(color, alpha, rgba) → {color}
cast the color array to 32 bit int ARGB color
Name | Type | Description |
---|---|---|
color | * | the color to cast, |
alpha | number | alpha value of the color output, 0 - 255 |
rgba | boolean | optional, if true, output in RRGGBBAA format |
- See
- parseColor for input options
- to24BitRGB
a 32bit int color
- Type:
- color
(static) toCSSString(color, alpha, forceHex) → {string}
cast the color to css string
Name | Type | Description |
---|---|---|
color | * | input color |
alpha | number | optional, alpha value between 0-1 |
forceHex | boolean | optional, if true and alpha is used, return color in #rrggbbaa, this notation may not be supported on old browsers |
- Tutorials
the result css string
- Type:
- string
(static) triadColor(n, range1, range2, range3, ref, sat, bri) → {Array}
Generate a bunch of color according to the traid color scheme
Name | Type | Description |
---|---|---|
n | number | number of colors |
range1 | number | |
range2 | number | |
range3 | number | |
ref | number | optional, reference angle, default is random |
sat | number | optional, float, 0 - 1, default to 1 |
bri | number | optional, float, 0 - 1, default to 1 |
- Tutorials
- See
- standerHarmonyColor
an array of colors in RGB format
- Type:
- Array
(static) triadMixing(color1, color2, color3, greyControl) → {Array}
mix 3 color to get a new one, use the greyControl to control the grey value (0:low -1:high)
Name | Type | Description |
---|---|---|
color1 | * | first color to mix, see parseColor |
color2 | * | second color to mix, see parseColor |
color3 | * | third color to mix, see parseColor |
greyControl | number | 0-1, how much grey get mix in |
- Tutorials
- See
- parseColor
a color array in RGB format
- Type:
- Array
(static) yiq(color) → {boolean}
YIQ color contrast calculation, returning black or white determination of optimal foreground color
Name | Type | Description |
---|---|---|
color | * | the foreground color, |
- Tutorials
- See
- parseColor
true for black(dark color) and false for white(bright color)
- Type:
- boolean