Skip to content

Instantly share code, notes, and snippets.

@johannesberdin
Created March 26, 2018 17:50
Show Gist options
  • Save johannesberdin/7cef1510dd90f73d26166c0e980c2517 to your computer and use it in GitHub Desktop.
Save johannesberdin/7cef1510dd90f73d26166c0e980c2517 to your computer and use it in GitHub Desktop.
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