rgb2hsl
Sat Feb 19 2022 00:52:18 GMT+0000 (Coordinated Universal Time)
Saved by
@daemondevin
#javascript
const rgb2hsl = (r,g,b) => {
const [r1,g1,b1] = [r/255, g/255, b/255];
const [cmax, cmin] = [Math.max(r1,g1,b1), Math.min(r1,g1,b1)];
const d = (cmax - cmin);
const L = (cmax + cmin) / 2;
const S = d == 0 ? 0 : (d / ( 1 - Math.abs(2*L-1)));
const H = d == 0 ? 0 :
cmax == r1 ? (60 * (((g1 - b1) / d) % 6)) :
cmax == g1 ? (60 * (((b1 - r1) / d) + 2)) :
(60 * (((r1 - g1) / d) + 4));
return [H, S, L];
};
content_copyCOPY
Coverts RGB values to HSL
Comments