Skip to content

Instantly share code, notes, and snippets.

@thiphariel
Created November 3, 2014 14:57
Show Gist options
  • Select an option

  • Save thiphariel/02b7c2651a6ddb8315c6 to your computer and use it in GitHub Desktop.

Select an option

Save thiphariel/02b7c2651a6ddb8315c6 to your computer and use it in GitHub Desktop.
Light color detection
/**
* Light color detection
* source : http://en.wikipedia.org/wiki/YIQ
*/
var light = function(hex) {
var r = parseInt(hex.substr(0, 2), 16);
var g = parseInt(hex.substr(2, 2), 16);
var b = parseInt(hex.substr(4, 2), 16);
var yiq = ((r * 299) + (g * 587) + (b * 114)) / 1000;
return yiq <= 196;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment