What is it?

This is a port of the randomColor.js script created by David Merfield.

RandomColor generates attractive colors by default. More specifically, RandomColor produces bright colors with a reasonably high saturation. This makes randomColor particularly useful for data visualizations and generative art.

Get the code on GitHub   

Examples

Once you have included RandomColor.class.php on your app, calling RandomColor::one($options) or RandomColor::many($count, $options) will return a random attractive color. Beneath is the live output of 36 generations.

RandomColor::many(36);

You can also pass an options object to randomColor. This allows you to specify the hue, luminosity and the format of colors to generate.

Format

  RandomColor::one(array('format'=>'hex'));
  // "#b21048"

RandomColor::one(array('format'=>'hsv'));
  // array('h'=>339,'s'=>91,'v'=>70)

RandomColor::one(array('format'=>'hsl'));
  // array('h'=>339,'s'=>83.4899999999999948840923025272786617279052734375,'l'=>38.1499999999999914734871708787977695465087890625)

RandomColor::one(array('format'=>'rgb'));
  // array('r'=>178.0,'g'=>16.0,'b'=>72.0)

RandomColor::one(array('format'=>'hslCss'));
  // "hsl(339,83.49%,38.15%)"

RandomColor::one(array('format'=>'rgbCss'));
  // "rgb(178,16,72)"

RandomColor::one(array('format'=>'hexa'));
  
Warning: Undefined array key "a" in /users/quirl/www/filemanager/spark/protected/vendor/mistic100/randomcolor/src/RandomColor.php on line 111
// "#b2104800" RandomColor::one(array('format'=>'hsva')); // array('h'=>339,'s'=>91,'v'=>70) RandomColor::one(array('format'=>'hsla'));
Warning: Undefined array key "a" in /users/quirl/www/filemanager/spark/protected/vendor/mistic100/randomcolor/src/RandomColor.php on line 79
// array('h'=>339,'s'=>83.4899999999999948840923025272786617279052734375,'l'=>38.1499999999999914734871708787977695465087890625,'a'=>NULL) RandomColor::one(array('format'=>'rgba'));
Warning: Undefined array key "a" in /users/quirl/www/filemanager/spark/protected/vendor/mistic100/randomcolor/src/RandomColor.php on line 95
// array('r'=>178.0,'g'=>16.0,'b'=>72.0,'a'=>NULL) RandomColor::one(array('format'=>'hslaCss'));
Warning: Undefined array key "a" in /users/quirl/www/filemanager/spark/protected/vendor/mistic100/randomcolor/src/RandomColor.php on line 88
// "hsla(339,83.49%,38.15%,)" RandomColor::one(array('format'=>'rgbaCss'));
Warning: Undefined array key "a" in /users/quirl/www/filemanager/spark/protected/vendor/mistic100/randomcolor/src/RandomColor.php on line 104
// "rgba(178,16,72,)"

Similar colors

RandomColor::many(18, array('hue'=>'red'));
RandomColor::many(18, array('hue'=>'orange'));
RandomColor::many(18, array('hue'=>'yellow'));
RandomColor::many(18, array('hue'=>'green'));
RandomColor::many(18, array('hue'=>'blue'));
RandomColor::many(18, array('hue'=>'purple'));
RandomColor::many(18, array('hue'=>'pink'));
RandomColor::many(18, array('hue'=>'monochrome'));

Multiple colors

RandomColor::many(27, array('hue'=>array('blue', 'yellow')));

Light colors

RandomColor::many(27, array('luminosity'=>'light'));

Dark colors

RandomColor::many(27, array('luminosity'=>'dark'));

Truly random colors

RandomColor::many(36, array('luminosity'=>'random', 'hue'=>'random'));

Random alpha

RandomColor::many(18, array('format' => 'rgbaCss'));
Get this on GitHub