MCPcopy Index your code
hub / github.com/figma/plugin-samples / hslToRgbFloat

Function hslToRgbFloat

variables-import-export/code.js:257–278  ·  view source on GitHub ↗
(h, s, l)

Source from the content-addressed store, hash-verified

255}
256
257function hslToRgbFloat(h, s, l) {
258 const hue2rgb = (p, q, t) => {
259 if (t < 0) t += 1;
260 if (t > 1) t -= 1;
261 if (t < 1 / 6) return p + (q - p) * 6 * t;
262 if (t < 1 / 2) return q;
263 if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
264 return p;
265 };
266
267 if (s === 0) {
268 return { r: l, g: l, b: l };
269 }
270
271 const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
272 const p = 2 * l - q;
273 const r = hue2rgb(p, q, (h + 1 / 3) % 1);
274 const g = hue2rgb(p, q, h % 1);
275 const b = hue2rgb(p, q, (h - 1 / 3) % 1);
276
277 return { r, g, b };
278}

Callers 1

parseColorFunction · 0.85

Calls 1

hue2rgbFunction · 0.85

Tested by

no test coverage detected