to_hex = function to_hex([R, G, B]) {
R = Math.round(0xff * R), G = Math.round(0xff * G), B = Math.round(0xff * B);
if (Math.max(R, G, B) > 255 || Math.min(R, G, B) < 0) {
throw new Error('Bad Input: R, G, and B must be in range [0, 1]'); }
return '#' + (1 << 24 | R << 16 | G << 8 | B).toString(16).slice(1);
}