-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_options.js
125 lines (114 loc) · 2.96 KB
/
generate_options.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
GENERATE_MODES = {
'HSB: H(R) S(80) B(80)': () => HSBtoRGB(int(random(360)), 80, 80),
'HSB: H(R) S(100) B(100)': () => HSBtoRGB(int(random(360)), 100, 100),
'RGB: Rand(100-255)': () => [random(100, 255), random(100, 255), random(100, 255), 255],
'RGB: Random(0-255)': () => [random(0, 255), random(0, 255), random(0, 255), 255],
'H(R(a-A)) S(R(a-A)) B(R(a-A))': function generateHueRange() {
let h;
let s;
let b;
if (config.minA >= config.maxA) {
h = config.minA;
} else {
h = int(random(config.minA, config.maxA));
}
if (config.minB >= config.maxB) {
s = config.minB;
} else {
s = int(random(config.minB, config.maxB));
}
if (config.minC >= config.maxC) {
b = config.minC;
} else {
b = int(random(config.minC, config.maxC));
}
return HSBtoRGB(h, s, b);
},
'R(R(a-A)) G(R(a-A)) B(R(a-A))': function generateRGBRange() {
let r;
let g;
let b;
if (config.minA == config.maxA) {
r = config.minA;
} else {
r = int(random(config.minA, config.maxA));
}
if (config.minB == config.maxB) {
g = config.minB;
} else {
g = int(random(config.minB, config.maxB));
}
if (config.minC == config.maxC) {
b = config.minC;
} else {
b = int(random(config.minC, config.maxC));
}
return [r, g, b, 255];
},
'Red: R(R) G(0) B(0)': () => [random(0, 255), 0, 0, 255],
'Green: R(0) G(R) B(0)': () => [0, random(0, 255), 0, 255],
'Blue: R(0) B(0) G(R)': () => [0, 0, random(0, 255), 255],
'RedGreen: R(R) G(R) B(0)': () => [random(0, 255), random(0, 255), 0, 255],
'RedBlue: R(R) G(0) B(R)': () => [random(0, 255), 0, random(0, 255), 255],
'BlueGreen: R(0) G(R) B(R)': () => [0, random(0, 255), random(0, 255), 255],
Image: 'Image',
};
// http://kickjava.com/src/org/eclipse/swt/graphics/RGB.java.htm
function HSBtoRGB(_hue, _saturation, _brightness) {
let r;
let g;
let b;
let hue = _hue;
const saturation = _saturation / 100;
const brightness = _brightness / 100;
if (saturation == 0) {
r = g = b = brightness;
} else {
if (hue == 360) {
hue = 0;
}
hue /= 60;
const i = int(hue);
const f = hue - i;
const p = brightness * (1 - saturation);
const q = brightness * (1 - saturation * f);
const t = brightness * (1 - saturation * (1 - f));
switch (i) {
case 0:
r = brightness;
g = t;
b = p;
break;
case 1:
r = q;
g = brightness;
b = p;
break;
case 2:
r = p;
g = brightness;
b = t;
break;
case 3:
r = p;
g = q;
b = brightness;
break;
case 4:
r = t;
g = p;
b = brightness;
break;
case 5:
default:
r = brightness;
g = p;
b = q;
break;
}
}
r = Math.round(r * 255);
g = Math.round(g * 255);
b = Math.round(b * 255);
return [r, g, b, 255];
}