1 function perc2color(perc) {
2 var r, g, b = 0;
3 if (perc < 50) {
4 r = 255;
5 g = Math.round(5.1 * perc);
6 }
7 else {
8 g = 255;
9 r = Math.round(510 - 5.10 * perc);
10 }
11 var h = r * 0x10000 + g * 0x100 + b * 0x1;
12 return '#' + ('000000' + h.toString(16)).slice(-6);
13 }