Skip to content

Instantly share code, notes, and snippets.

@thers
Last active November 27, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thers/4d2cd42d2488056e8df8 to your computer and use it in GitHub Desktop.
Save thers/4d2cd42d2488056e8df8 to your computer and use it in GitHub Desktop.
function hsl2rgb(h,s,l){s=s/100;l=l/100;var c,x,m,rgb;c=(1-Math.abs(2*l-1))*s;x=c*(1-Math.abs(((h/60)%2)-1));m=l-c/2;if(h>=0&&h<60)rgb=[c,x,0];if(h>=60&&h<120)rgb=[x,c,0];if(h>=120&&h<180)rgb=[0,c,x];if(h>=180&&h<240)rgb=[0,x,c];if(h>=240&&h<300)rgb=[x,0,c];if(h>=300&&h<360)rgb=[c,0,x];return rgb.map(v=>255*(v+m)|0);}
hsl2rgb(145, 80, 50); // [25, 229, 110]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment