Last active
December 22, 2015 00:29
-
-
Save dougalcampbell/6389543 to your computer and use it in GitHub Desktop.
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
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment