Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ var color = randomColor(); // a hex code for an attractive color

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. If you pass a hexidecimal color string such as ```#00FFFF```, randomColor will extract its hue value and use that to generate colors.
```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. If you pass a hexadecimal color string such as ```#00FFFF```, randomColor will extract its hue value and use that to generate colors.

```luminosity``` – Controls the luminosity of the generated color. You can specify a string containing ```bright```, ```light``` or ```dark```.
```luminosity``` – Controls the luminosity of the generated color. You can specify a string containing ```bright```, ```light```, ```dark``` or ```muted```.

```count``` – An integer which specifies the number of colors to generate.

```seed``` - An integer or string which when passed will cause randomColor to return the same color each time.
```seed``` - An integer or string which, when passed, will cause randomColor to return the same color each time.

```format``` – A string which specifies the format of the generated color. Possible values are ```rgb```, ```rgba```, ```rgbArray```, ```hsl```, ```hsla```, ```hslArray``` and ```hex``` (default).

Expand Down
13 changes: 7 additions & 6 deletions randomColor.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
// Populate the color dictionary
loadColorBounds();

// check if a range is taken
// Check if a range is taken
var colorRanges = [];

var randomColor = function (options) {
Expand All @@ -51,7 +51,7 @@
} else if (typeof options.seed === "string") {
seed = stringToInteger(options.seed);

// Something was passed as a seed but it wasn't an integer or string
// Something was passed as a seed, but it wasn't an integer or string
} else if (options.seed !== undefined && options.seed !== null) {
throw new TypeError("The seed value must be an integer or string");

Expand Down Expand Up @@ -133,7 +133,7 @@
var hueRange = getHueRange(options.hue);

hue = randomWithin(hueRange);
// Instead of storing red as two seperate ranges,
// Instead of storing red as two separate ranges,
// we group them, using negative numbers
if (hue < 0) {
hue = 360 + hue;
Expand Down Expand Up @@ -167,6 +167,7 @@
break;

case "light":
case "muted":
sMax = 55;
break;
}
Expand Down Expand Up @@ -313,7 +314,7 @@

function randomWithin(range) {
if (seed === null) {
//generate random evenly destinct number from : https://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/
//generate random evenly distinct number from: https://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/
var golden_ratio = 0.618033988749895;
var r = Math.random();
r += golden_ratio;
Expand Down Expand Up @@ -368,7 +369,7 @@

defineColor(
"red",
[-26, 18],
[-26, 18],//360-26=334
[
[20, 100],
[30, 92],
Expand Down Expand Up @@ -583,7 +584,7 @@
return total;
}

// get The range of given hue when options.count!=0
// get the range of given hue when options.count!=0
function getRealHueRange(colorHue) {
if (!isNaN(colorHue)) {
var number = parseInt(colorHue);
Expand Down