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

Function randomColor

randomColor.js:38–101  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

36 var colorRanges = [];
37
38 var randomColor = function (options) {
39 options = options || {};
40
41 // Check if there is a seed and ensure it's an
42 // integer. Otherwise, reset the seed value.
43 if (
44 options.seed !== undefined &&
45 options.seed !== null &&
46 options.seed === parseInt(options.seed, 10)
47 ) {
48 seed = options.seed;
49
50 // A string was passed as a seed
51 } else if (typeof options.seed === "string") {
52 seed = stringToInteger(options.seed);
53
54 // Something was passed as a seed but it wasn't an integer or string
55 } else if (options.seed !== undefined && options.seed !== null) {
56 throw new TypeError("The seed value must be an integer or string");
57
58 // No seed, reset the value outside.
59 } else {
60 seed = null;
61 }
62
63 var H, S, B;
64
65 // Check if we need to generate multiple colors
66 if (options.count !== null && options.count !== undefined) {
67 var totalColors = options.count,
68 colors = [];
69 // Value false at index i means the range i is not taken yet.
70 for (var i = 0; i < options.count; i++) {
71 colorRanges.push(false);
72 }
73 options.count = null;
74
75 while (totalColors > colors.length) {
76 var color = randomColor(options);
77
78 if (seed !== null) {
79 options.seed = seed;
80 }
81
82 colors.push(color);
83 }
84
85 options.count = totalColors;
86
87 return colors;
88 }
89
90 // First we pick a hue (H)
91 H = pickHue(options);
92
93 // Then use H to determine saturation (S)
94 S = pickSaturation(H, options);
95

Callers 4

vFunction · 0.85
iFunction · 0.85
renderLogoFunction · 0.85
renderDemoFunction · 0.85

Calls 5

stringToIntegerFunction · 0.85
pickHueFunction · 0.85
pickSaturationFunction · 0.85
pickBrightnessFunction · 0.85
setFormatFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…