Skip to content

Instantly share code, notes, and snippets.

@DavideMontersino
Created September 29, 2014 09:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavideMontersino/ffad0ae130db5f82e19f to your computer and use it in GitHub Desktop.
Save DavideMontersino/ffad0ae130db5f82e19f to your computer and use it in GitHub Desktop.
// From http://www.nbdtech.com/Blog/archive/2008/04/27/Calculating-the-Perceived-Brightness-of-a-Color.aspx
// returns a number in the rage of 0 (black) to 255 (White) and to set the foreground color based on the Brightness method
// c is an array where 0 is red, 1 is green, 2 is blue
//rgb values are on a 0 - 255 scale
var colorBrightness = function(c){
return Math.sqrt(
c[0] * c[0] * .241 +
c[1] * c[1] * .691 +
c[2] * c[2] * .068);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment