public
Last active

For future reference... The W3C-suggested algorithm for converting HSL color to RGB. In the funky ABC pseudo-code. http://www.w3.org/TR/2011/REC-css3-color-20110607/#hsl-color

  • Download Gist
hsl2rgb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
HOW TO RETURN hsl.to.rgb(h, s, l):
SELECT:
l<=0.5: PUT l*(s+1) IN m2
ELSE: PUT l+s-l*s IN m2
PUT l*2-m2 IN m1
PUT hue.to.rgb(m1, m2, h+1/3) IN r
PUT hue.to.rgb(m1, m2, h ) IN g
PUT hue.to.rgb(m1, m2, h-1/3) IN b
RETURN (r, g, b)
 
HOW TO RETURN hue.to.rgb(m1, m2, h):
IF h<0: PUT h+1 IN h
IF h>1: PUT h-1 IN h
IF h*6<1: RETURN m1+(m2-m1)*h*6
IF h*2<1: RETURN m2
IF h*3<2: RETURN m1+(m2-m1)*(2/3-h)*6
RETURN m1

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.