Skip to content

Instantly share code, notes, and snippets.

@JDMCreator
Last active May 18, 2017 20:21
Show Gist options
  • Save JDMCreator/5f2f538e3bfd2bd5b15dee14dafd015d to your computer and use it in GitHub Desktop.
Save JDMCreator/5f2f538e3bfd2bd5b15dee14dafd015d to your computer and use it in GitHub Desktop.
HSL to RGB // IE9+ // 174 bytes
/*
Returns a [R,G,B] array. [R,G,B] are [0,255] numbers. [h,s,l] are [0,1] numbers
*/
function(h, s, l){
s=l < 0.5 ? l * (1 + s) : l + s - l * s,
l = 2 * l - s;
return [h+1/3,h,h-1/3].map(function(t,c){
return (((c=s-l,t+=t<0?1:t>1?-1:0)<1/6?l+6*c*t:.5>t?s:t<2/3?l+c*(2/3-t)*6:l)*255)+.5|0;
});
}
function(b,c,a){c=.5>a?a*(1+c):a+c-a*c;a=2*a-c;return[b+1/3,b,b-1/3].map(function(d,b){return 255*((b=c-a,d+=0>d?1:1<d?-1:0)<1/6?a+6*b*d:.5>d?c:d<2/3?a+b*(2/3-d)*6:a)+.5|0})}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment