Skip to content

Instantly share code, notes, and snippets.

@SoftwareDevPro
Created October 30, 2016 05:27
Show Gist options
  • Save SoftwareDevPro/9248ae04e8695ea08a66400ea33eaecb to your computer and use it in GitHub Desktop.
Save SoftwareDevPro/9248ae04e8695ea08a66400ea33eaecb to your computer and use it in GitHub Desktop.
Takes a HSL (hue saturation, light) value and returns the RGB equivalent
# Filed under: color, convert, hsl, rgb
# Converts hue-saturation-lightness to red-green-blue color value.
###
@param a hue
@param b saturation
@param c lightness
###
hsl2rgb = (a, b, c) ->
a *= 6
b = [
(if c += b *= c < .5 then c else 1 - c),
c - a % 1 * b * 2,
c -= b *= 2,
c,
c + a % 1 * b,
c + b
]
red = b[~~a % 6]
green = b[(a|16) % 6]
blue = b[(a|8) % 6]
[red, green, blue]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment