I've borrowed the formulas to compute the contrast and brightness difference between two colors from the W3C.
If the RGB components of the first color are r1,g1,b1 and of the second color are r2,g2,b2 then:
To get a good result c should be greater than 500 and d greater than 125.
To simulate the color deficiences, I just copied the source code of the gimp (an image manipulation program) module and ported it to javascript.
The gimp version I used is 2.3 and the algorithm is based on an article by Hans Brettel, Francoise Vienot and John Mollon in the Journal of the Optical Society of America V14(10), pg 2647. (See http://vischeck.com/ for more info). The credits for this algorithm are at the end of the page.
Javascript isn't the optimum for the number crunching the algorithm requires, so the results aren't identical to the ones in gimp.
Anyway they're are not too bad and almost always they look very similar.
After computing the new colors by this algorithm I calculate c and d for them.
If all 4 values (normal,deuteranope,protanope and tritanope) are good, the script displays OK!.
Keep in mind that tritanopia is very rare.
That's all. If you have any proposal to improve the page, the javascript code , the layout or whatever, just mail me at gmazzocato@gmail.com. This is an open project and I would be glad to improve it!
The authors of the gimp module are:
Go to the accessibility color wheel