-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhlstorgb.js
72 lines (59 loc) · 1.32 KB
/
hlstorgb.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
function ConverterHSLToRGB(h, s, l){
var h = h/360;
var s = s/100;
var l = l/100;
var r = l;
var g = l;
var b = l;
var v = (l <= 0.5) ? (l * (1.0 + s)) : (l + s - l * s);
if(v > 0){
var m;
var sv;
var sextant;
var fract;
var vsf;
var mid1;
var mid2;
m = l + l - v;
sv = (v - m) / v;
h = h * 6.0;
sextant = Math.floor(h);
fract = h - sextant;
vsf = v * sv * fract;
mid1 = m + vsf;
mid2 = v - vsf;
switch(sextant){
case 0:
r = v;
g = mid1;
b = m;
break;
case 1:
r = mid2;
g = v;
b = m;
break;
case 2:
r = m;
g = v;
b = mid1;
break;
case 3:
r = m;
g = mid2;
b = v;
break;
case 4:
r = mid1;
g = m;
b = v;
break;
case 5:
r = v;
g = m;
b = mid2;
break;
}
}
return parseInt(r * 255.0)+','+parseInt(g * 255.0)+','+parseInt(b * 255.0);
}