-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (57 loc) · 1.83 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Returns a random integer between min (included) and max (included)
// Math.floor because Math.round() yields non-uniform distribution
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
const getRandomIntInclusive = (min, max) => {
return Math.floor(Math.random() * (max - min + 1)) + min;
};
export default () => {
// Seed the primary color
const hue = getRandomIntInclusive(1, 359);
// Comment out above line and uncomment below to test specific values
// const hue = 9; // 128 173 (test values)
// Derive complement (secondary) hue
var complement = hue > 180 ? hue - 180 : hue + 179;
// analogous (tertiary) hue
var analogous;
switch (hue) {
case hue < 135:
analogous = hue + 224;
break;
case hue > 224:
analogous = hue - 223;
break;
default:
var shift = hue + 225;
analogous = shift > 359 ? shift - 359 : shift;
}
// Seed random saturation and lightness values within acceptable parameters
const saturation = `${getRandomIntInclusive(80, 100)}%`;
// highlight
const xlight = `${getRandomIntInclusive(84, 92)}%`;
// more extreme lightness
const lighter = `${getRandomIntInclusive(76, 84)}%`;
// very light or white text
const lightness = `${getRandomIntInclusive(64, 72)}%`;
// mid value used for lightness and saturation
const midrange = `${getRandomIntInclusive(48, 64)}%`;
// dark highlight
const lowmid = `${getRandomIntInclusive(28, 36)}%`;
// very dark or black text
const darkness = `${getRandomIntInclusive(16, 24)}%`;
// more extreme darkness
const darker = `${getRandomIntInclusive(0, 12)}%`;
// mixing values
return {
hue: hue,
complement: complement,
analogous: analogous,
saturation: saturation,
xlight: xlight,
lighter: lighter,
lightness: lightness,
midrange: midrange,
lowmid: lowmid,
darkness: darkness,
darker: darker,
};
};