Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
color-blind simulation
var blinder = require('color-blind');
var colorBlindWatch = $('.color-blind-watch');
var colorBlindResult = $('.color-blind-result-watch');
var randomColor = '#000000';
window.setInterval(function(){
randomColor = '#'+ ('000000' + Math.floor(Math.random()*16777215).toString(16)).slice(-6);
colorBlindFn(randomColor);
}, 1000);
var colorBlindFn = function(color) {
var anomaly = parseInt($('.color-blind-select').val());
switch (anomaly) {
case 1:
result = blinder.protanomaly(color);
break;
case 2:
result = blinder.protanopia(color);
break;
case 3:
result = blinder.deuteranomaly(color);
break;
case 4:
result = blinder.deuteranopia(color);
break;
case 5:
result = blinder.tritanomaly(color);
break;
case 6:
result = blinder.tritanopia(color);
break;
case 7:
result = blinder.achromatomaly(color);
break;
case 8:
result = blinder.achromatopsia(color);
break;
}
colorBlindWatch.text(color);
colorBlindWatch.css('background-color', color);
colorBlindResult.text(result);
colorBlindResult.css('background-color', result);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.