Skip to content

Instantly share code, notes, and snippets.

@akdetrick
Last active December 25, 2015 09:39
Show Gist options
  • Select an option

  • Save akdetrick/6955652 to your computer and use it in GitHub Desktop.

Select an option

Save akdetrick/6955652 to your computer and use it in GitHub Desktop.
converts hex to yiq color brightness
var R = parseInt(hex.substring(0,2),16),
G = parseInt(hex.substring(2,4),16),
B = parseInt(hex.substring(4,6),16);
// luminance as weighted sum of the R, G, and B values
var luma = Math.sqrt(R * R * .241 + G * G * .691 + B * B * .068);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment