Created
October 30, 2016 05:24
-
-
Save SoftwareDevPro/52fd9ae96c8f3410ce9ef4527bfc24a8 to your computer and use it in GitHub Desktop.
Receives a hex string, and returns an array of R,G,B components
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
# Filed under: hex, color, rgb | |
# Converts a hex string to RGB. | |
### | |
@param a a "#xxxxxx" hex string, | |
### | |
hex2rgb = (a) -> | |
### | |
turn it into a number by taking the hexadecimal prefix and the | |
numerical portion, and if the #xxxxxx form is used replace each | |
character with itself twice. | |
### | |
a = +("0x" + a.slice(1).replace(a.length > 4 && /./g, '$&$&')) | |
### | |
return an array with red, blue, and green components. | |
### | |
[ a >> 16, a >> 8 & 255, a & 255 ] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment