Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Converts an HSL value to RGB
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];
};
@morkro

This comment has been minimized.

Copy link

commented Apr 18, 2016

Your method is still named HSLToRBG. Should be HSLToRGB 🙋

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.