Random color is a simple javascript module for generating random colors that contrast enough to distinguish between one another, and are not too loud (by default, all colours can have readable black/dark font overlayed).
Useful, for example, in charts and diagrams where X number of series need to be distinguished by color.
Random Color can be accessed via the global namespace, or as a RequireJS or CommonJS module. See the sample (refresh to regenerate).
The module returns an object prototype for you to instantiate:
var color = new RColor;
var c1 = color.get();
// c1 = [121, 197, 243] (rgb value)
var c2 = color.get(true);
// c2 = "#79C5F3" (hex value)
var c3 = color.get(true, 0.3, 0.99);
// c3 = "#F7FDB1" (hex value for lighter color)
Returns a random color based on the running hue property of the instantiated RColor object. If true is specified for returnHex, will return a string hex representation of the color with hash (#). Otherwise, returns an array of length 3 representing the RGB value of the color.
Method used internally by get to render RGB colors that are distinctly different via HSV and the golden ratio. For a great discussion on this visit Martin Ankerl's blog post which forms the inspiration for this module.
A float value maintained during the life of the RColor object in order to ensure distinguishable colors.
Constant float value adjusts hue to ensure distinguishable colors.
Free to use and distribute under the MIT license.
Apologies in advance to my commonwealth friends, if you find 'color' vs. 'colour'. It was a hard decision for a Canadian. :)
Wes Johnson @SterlingWes