April 7, 2015

Random Color

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.

Options

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).

Examples

// 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)'
});

License

This project is licensed under the terms of the MIT license..

To do

It might be a good idea to consider using other color models.

  1. When returning an array of multiple colors, try to make each color as distinct as possible. Make sure each color is distinct to its neighbours.
  2. Improve attractive dark color generation, currently they’re a touch murky.
  3. Improve the color dictionary
  1. Think about using and returning seeds.
  2. Think about adding feature to return complementary & contrasting colors, as well as color triads, tetrads etc. Other libraries might already do this better though.
  3. Think about adding a scheme options which would return a dominant color, as well as secondary, tertiary color and primary and secondary text colors. This might be a bad idea.

http://indiegamr.com/generate-repeatable-random-numbers-in-js/




Previous post A Meditation upon a Broomstick A classic piece of parody from Jonathan Swift. The butt of Swift’s pen in this instance was Robert Boyle and his Occasional Reflections upon Next post John Oliver interviews Edward Snowden There are very few government checks on what America’s sweeping surveillance programs are capable of doing. John Oliver sits down with Edward