A tiny script for generating attractive random colors. See the results on the demo.
randomColor is available minified on cdnjs. It is also distributed on npm and bower.
npm install randomcolor
randomColor has been ported to C#, Go, PHP, Python and Swift.
You can pass an options object to influence the type of color it produces. The options object accepts the following properties:
Hue — Controls the hue of the generated color. You can pass a string representing a color name: red, orange, yellow, green, blue, purple, pink and monochrome are currently supported.
Luminosity — Controls the luminosity of the generated color. You can specify a string containing bright, light or dark.
Count — An integer which specifies the number of colors to generate.
Format — A string which specifies the format of the generated color. Possible values are rgb, rgbArray, hsl, hslArray and hex (default).
// Returns a hex code for an attractive color
randomColor();
// Returns an array of ten green colors
randomColor({
count: 10,
hue: 'green'
});
// Returns a hex code for a light blue
randomColor({
luminosity: 'light',
hue: 'blue'
});
// Returns a hex code for a 'truly random' color
randomColor({
luminosity: 'random',
hue: 'random'
});
// Returns a bright color in RGB
randomColor({
luminosity: 'bright',
format: 'rgb' // e.g. 'rgb(225,200,20)'
});
This project is licensed under the terms of the MIT license..
It might be a good idea to consider using other color models.
http://indiegamr.com/generate-repeatable-random-numbers-in-js/