Created
April 7, 2016 15:45
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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