MCPcopy Index your code
hub / github.com/davidmerfield/randomColor / pickHue

Function pickHue

randomColor.js:103–144  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

101 };
102
103 function pickHue(options) {
104 if (colorRanges.length > 0) {
105 var hueRange = getRealHueRange(options.hue);
106
107 var hue = randomWithin(hueRange);
108
109 //Each of colorRanges.length ranges has a length equal approximatelly one step
110 var step = (hueRange[1] - hueRange[0]) / colorRanges.length;
111
112 var j = parseInt((hue - hueRange[0]) / step);
113
114 //Check if the range j is taken
115 if (colorRanges[j] === true) {
116 j = (j + 2) % colorRanges.length;
117 } else {
118 colorRanges[j] = true;
119 }
120
121 var min = (hueRange[0] + j * step) % 359,
122 max = (hueRange[0] + (j + 1) * step) % 359;
123
124 hueRange = [min, max];
125
126 hue = randomWithin(hueRange);
127
128 if (hue < 0) {
129 hue = 360 + hue;
130 }
131 return hue;
132 } else {
133 var hueRange = getHueRange(options.hue);
134
135 hue = randomWithin(hueRange);
136 // Instead of storing red as two seperate ranges,
137 // we group them, using negative numbers
138 if (hue < 0) {
139 hue = 360 + hue;
140 }
141
142 return hue;
143 }
144 }
145
146 function pickSaturation(hue, options) {
147 if (options.hue === "monochrome") {

Callers 1

randomColorFunction · 0.85

Calls 3

getRealHueRangeFunction · 0.85
randomWithinFunction · 0.85
getHueRangeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…