|
| 1 | +# Random Color |
| 2 | + |
| 3 | +For generating attractive random colors. |
| 4 | + |
| 5 | +This is a PHP port of David Merfield [randomColor](https://github.com/davidmerfield/randomColor) Javascript utility. |
| 6 | + |
| 7 | +See the results on [the demo](http://www.strangeplanet.fr/work/RandomColor.php). |
| 8 | + |
| 9 | +[](http://www.strangeplanet.fr/work/RandomColor.php) |
| 10 | + |
| 11 | +### Options |
| 12 | + |
| 13 | +You can pass an options object to influence the type of color it produces. The options object accepts the following properties: |
| 14 | + |
| 15 | +**Hue** – Controls the hue of the generated color. You can pass a string representing a color name (e.g. 'orange'). Possible color names are *red, orange, yellow, green, blue, purple, pink and monochrome*. |
| 16 | + |
| 17 | +**Luminosity** – Controls the luminosity of the generated color. You can pass a string containing *bright, light or dark*. |
| 18 | + |
| 19 | +**Format** – A string which specifies the format of the generated color. Possible values are *hsv, hsl, hslCss, rgb, rgbCss, and hex*. |
| 20 | + |
| 21 | +### Examples |
| 22 | + |
| 23 | +```php |
| 24 | + |
| 25 | +// Returns a hex code for an attractive color |
| 26 | +RandomColor::one(); |
| 27 | + |
| 28 | +// Returns an array of ten green colors |
| 29 | +RandomColor::many(10, array( |
| 30 | + 'hue' => 'green' |
| 31 | +)); |
| 32 | + |
| 33 | +// Returns a hex code for a light blue |
| 34 | +RandomColor::one(array( |
| 35 | + 'luminosity' => 'light', |
| 36 | + 'hue' => 'blue' |
| 37 | +)); |
| 38 | + |
| 39 | +// Returns a hex code for a 'truly random' color |
| 40 | +RandomColor::one(array( |
| 41 | + 'luminosity' => 'random', |
| 42 | + 'hue' => 'random' |
| 43 | +)); |
| 44 | + |
| 45 | +// Returns a bright color in RGB |
| 46 | +RandomColor::one(array( |
| 47 | + 'luminosity' => 'bright', |
| 48 | + 'format' => 'rgbCss' // e.g. 'rgb(225,200,20)' |
| 49 | +)); |
| 50 | +``` |
| 51 | + |
| 52 | +### Other languages |
| 53 | + |
| 54 | +RandomColor is available in [JavaScript](https://github.com/davidmerfield/randomColor), [c#](https://github.com/nathanpjones/randomColorSharped) and [go](https://github.com/hansrodtang/randomcolor). |
| 55 | + |
| 56 | +### License |
| 57 | + |
| 58 | +This project is licensed under the terms of the MIT license. |
0 commit comments