Created
March 22, 2013 21:59
-
-
Save joeLepper/5225111 to your computer and use it in GitHub Desktop.
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
var hslToRgb = function(hue, satch, lite) { | |
var mod1 | |
, mod2 | |
, hue | |
, hugh | |
, red | |
, green | |
, blue; | |
satch /=100; | |
lite /= 100; | |
if (satch == 0){ | |
red = green = blue = (lite * 255); | |
} | |
else { | |
if (lite <= 0.5){ | |
mod2 = lite * (satch + 1); | |
} | |
else{ | |
mod2 = lite + satch - lite * satch; | |
} | |
mod1 = lite * 2 - mod2; | |
hugh = hue / 360; | |
red = hueToRgb(mod1, mod2, hugh + 1/3); | |
green = hueToRgb(mod1, mod2, hugh); | |
blue = hueToRgb(mod1, mod2, hugh - 1/3); | |
} | |
return {red: red, green: green, blue: blue}; | |
} | |
, hueToRgb = function(mod1, mod2, hue) { | |
var value; | |
if (hue < 0){ | |
hue += 1; | |
} | |
else if (hue > 1){ | |
hue -= 1; | |
} | |
if (6 * hue < 1){ | |
value = mod1 + (mod2 - mod1) * hue * 6; | |
} | |
else if (2 * hue < 1){ | |
value = mod2; | |
} | |
else if (3 * hue < 2){ | |
value = mod1 + (mod2 - mod1) * (2/3 - hue) * 6; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment