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
|
/**
* Iquizeles color generator
* @module lib/color.js;
*/
const palettes = [
[
[0.5, 0.5, 0.5],
[0.5, 0.5, 0.5],
[1.0, 1.0, 1.0],
[0.0, 0.33, 0.67],
],
[
[0.5, 0.5, 0.5],
[0.5, 0.5, 0.5],
[1.0, 1.0, 1.0],
[0.0, 0.1, 0.2],
],
[
[0.5, 0.5, 0.5],
[0.5, 0.5, 0.5],
[1.0, 1.0, 1.0],
[0.3, 0.2, 0.2],
],
[
[0.5, 0.5, 0.5],
[0.5, 0.5, 0.5],
[1.0, 1.0, 0.5],
[0.8, 0.9, 0.3],
],
[
[0.5, 0.5, 0.5],
[0.5, 0.5, 0.5],
[1.0, 0.7, 0.4],
[0.0, 0.15, 0.2],
],
[
[0.5, 0.5, 0.5],
[0.5, 0.5, 0.5],
[2.0, 1.0, 0.0],
[0.5, 0.2, 0.25],
],
[
[0.8, 0.5, 0.4],
[0.2, 0.4, 0.2],
[2.0, 1.0, 1.0],
[0.0, 0.25, 0.25],
],
];
let palette = palettes[0];
function channel(t, a, b, c, d, add, mul) {
return a + b * Math.cos(2 * Math.PI * (c * t + d)) * mul + add;
}
function color(t, add, mul, alpha) {
let a, b, c, d;
const rgb = [];
for (var i = 0; i < 3; i++) {
a = palette[0][i];
b = palette[1][i];
c = palette[2][i];
d = palette[3][i];
rgb[i] = Math.round(channel(-t, a, b, c, d, add, mul) * 255);
}
if (alpha) {
return "rgba(" + rgb + "," + alpha + ")";
}
return "rgb(" + rgb + ")";
}
export default color;
|