Skip to content

Instantly share code, notes, and snippets.

@SoftwareDevPro
Created October 30, 2016 05:24
Show Gist options
  • Save SoftwareDevPro/52fd9ae96c8f3410ce9ef4527bfc24a8 to your computer and use it in GitHub Desktop.
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
# 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