Skip to content

Instantly share code, notes, and snippets.

@nickgartmann
Created October 12, 2015 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickgartmann/0b7b1981aefe35c48564 to your computer and use it in GitHub Desktop.
Save nickgartmann/0b7b1981aefe35c48564 to your computer and use it in GitHub Desktop.
xy2rgb: function(x,y) {
var X = x/y;
var Y = 1;
var Z = ((1 - x - y)/y);
X = X / 100.0;
Y = Y / 100.0;
Z = Z / 100.0;
var R = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
var G = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
var B = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
if(R > 0.0031308) {
R = 1.055 * (Math.pow(R, (1/2.4))) - 0.055
} else { R = 12.92 * R }
if(G > 0.0031308) {
G = 1.055 * (Math.pow(G, (1/2.4))) - 0.055
} else { G = 12.92 * G }
if(B > 0.0031308) {
B = 1.055 * (Math.pow(B, (1/2.4))) - 0.055
} else { B = 12.92 * B }
return [R * 255,G * 255,B * 255];
}
@jmootrey
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment