Last active
June 1, 2016 10:24
-
-
Save PaulKinlan/d4053acfffd49abfa197a8d370a18337 to your computer and use it in GitHub Desktop.
Converts an HSL value to RGB
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
const HSLToRBG = (H, S, L) => { | |
// algo http://www.rapidtables.com/convert/color/hsl-to-rgb.htm | |
const C = (1 - Math.abs(2*L - 1)) * S; | |
const X = C * (1 - Math.abs(((H / 60) % 2)-1)); | |
const m = L - C/2; | |
const [r1, g1, b1] = H >= 0 && H < 60 ? [C, X, 0] : | |
H >= 60 && H < 120 ? [X, C, 0] : | |
H >= 120 && H < 180 ? [0, C, X] : | |
H >= 180 && H < 240 ? [0, X, C] : | |
H >= 240 && H < 300 ? [X, 0, C] : | |
[C, 0, X]; | |
return [(r1 + m) * 255, (g1 + m) * 255, (b1 + m) * 255]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your method is still named
HSLToRBG
. Should beHSLToRGB
🙋