({h, s, l, a = 1}: HSLA)
| 57 | |
| 58 | // https://en.wikipedia.org/wiki/HSL_and_HSV |
| 59 | export function hslToRGB({h, s, l, a = 1}: HSLA): RGBA { |
| 60 | if (s === 0) { |
| 61 | const [r, b, g] = [l, l, l].map((x) => Math.round(x * 255)); |
| 62 | return {r, g, b, a}; |
| 63 | } |
| 64 | |
| 65 | const c = (1 - Math.abs(2 * l - 1)) * s; |
| 66 | const x = c * (1 - Math.abs((h / 60) % 2 - 1)); |
| 67 | const m = l - c / 2; |
| 68 | const [r, g, b] = ( |
| 69 | h < 60 ? [c, x, 0] : |
| 70 | h < 120 ? [x, c, 0] : |
| 71 | h < 180 ? [0, c, x] : |
| 72 | h < 240 ? [0, x, c] : |
| 73 | h < 300 ? [x, 0, c] : |
| 74 | [c, 0, x] |
| 75 | ).map((n) => Math.round((n + m) * 255)); |
| 76 | |
| 77 | return {r, g, b, a}; |
| 78 | } |
| 79 | |
| 80 | // https://en.wikipedia.org/wiki/HSL_and_HSV |
| 81 | export function rgbToHSL({r: r255, g: g255, b: b255, a = 1}: RGBA): HSLA { |
no outgoing calls
no test coverage detected