Skip to content

Instantly share code, notes, and snippets.

@jameslkingsley
Created September 13, 2016 16:27
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 jameslkingsley/a9c67af8b2d7a78174e2360bc7faae26 to your computer and use it in GitHub Desktop.
Save jameslkingsley/a9c67af8b2d7a78174e2360bc7faae26 to your computer and use it in GitHub Desktop.
function colorMatrix(rgba, matrix) {
function fu(n) {return (n < 0 ? 0 : (n < 255 ? n : 255));}
var r = ((o.R * m[0]) + (o.G * m[1]) + (o.B * m[2]) + (o.A * m[3]) + m[4]);
var g = ((o.R * m[5]) + (o.G * m[6]) + (o.B * m[7]) + (o.A * m[8]) + m[9]);
var b = ((o.R * m[10]) + (o.G * m[11]) + (o.B * m[12]) + (o.A * m[13]) + m[14]);
var a = ((o.R * m[15]) + (o.G * m[16]) + (o.B * m[17]) + (o.A * m[18]) + m[19]);
return({
'R': fu(r),
'G': fu(g),
'B': fu(b),
'A': fu(a)
});
}
function blindType(type) {
return({
'Normal': [1,0,0,0,0, 0,1,0,0,0, 0,0,1,0,0, 0,0,0,1,0, 0,0,0,0,1],
'Protanopia': [0.567,0.433,0,0,0, 0.558,0.442,0,0,0, 0,0.242,0.758,0,0, 0,0,0,1,0, 0,0,0,0,1],
'Protanomaly': [0.817,0.183,0,0,0, 0.333,0.667,0,0,0, 0,0.125,0.875,0,0, 0,0,0,1,0, 0,0,0,0,1],
'Deuteranopia': [0.625,0.375,0,0,0, 0.7,0.3,0,0,0, 0,0.3,0.7,0,0, 0,0,0,1,0, 0,0,0,0,1],
'Deuteranomaly': [0.8,0.2,0,0,0, 0.258,0.742,0,0,0, 0,0.142,0.858,0,0, 0,0,0,1,0, 0,0,0,0,1],
'Tritanopia': [0.95,0.05,0,0,0, 0,0.433,0.567,0,0, 0,0.475,0.525,0,0, 0,0,0,1,0, 0,0,0,0,1],
'Tritanomaly': [0.967,0.033,0,0,0, 0,0.733,0.267,0,0, 0,0.183,0.817,0,0, 0,0,0,1,0, 0,0,0,0,1],
'Achromatopsia': [0.299,0.587,0.114,0,0, 0.299,0.587,0.114,0,0, 0.299,0.587,0.114,0,0, 0,0,0,1,0, 0,0,0,0,1],
'Achromatomaly': [0.618,0.320,0.062,0,0, 0.163,0.775,0.062,0,0, 0.163,0.320,0.516,0,0,0,0,0,1,0,0,0,0,0]
}[type]);
}
var color = colorMatrix({R: 255, G: 0, B: 0}, blindType('Tritanopia'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment