Skip to content

Instantly share code, notes, and snippets.

@klesouza
Created April 7, 2016 15:45
Show Gist options
  • Save klesouza/1cf19d10b66f3cc8418beaa8a1b529ab to your computer and use it in GitHub Desktop.
Save klesouza/1cf19d10b66f3cc8418beaa8a1b529ab to your computer and use it in GitHub Desktop.
Simple javascript method for converting graylevel (0..255 - from white to black) to hexadecimal color
function grayToHex(val) {
if(val >= 0 && val <= 255){
var n = (255 - val).toString(16);
return "#" + n + n + n;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment