Skip to content

Instantly share code, notes, and snippets.

@ssaurel
Created January 5, 2020 14:01
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 ssaurel/9b97fe2bd683e625bc60f4d0db027885 to your computer and use it in GitHub Desktop.
Save ssaurel/9b97fe2bd683e625bc60f4d0db027885 to your computer and use it in GitHub Desktop.
hexislight function for the Hexadecimal Color Clock on the SSaurel's Blog
function hexislight(color) {
var hex = color.replace('#', '');
var red = parseInt(hex.substr(0, 2), 16);
var green = parseInt(hex.substr(2, 2), 16);
var blue = parseInt(hex.substr(4, 2), 16);
// it is a known formula, nothing magical here
var brightness = ((red * 299) + (green * 587) + (blue * 114)) / 1000;
return brightness > 155;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment