Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function hslaConvert(p, q, t)
- {
- if (t < 0) t += 1;
- if (t > 1) t -= 1;
- if (t < 1/6) return p + (q - p) * 6 * t;
- if (t < 3/6) return q;
- if (t < 4/6) return p + (q - p) * 6 * (4/6 - t);
- return p
- }
- function hsla2rgba(h, s, l, a)
- {
- // thanks Mohsen! https://stackoverflow.com/a/9493060/460571
- let p, q, r, g, b;
- if (l < 0.5)
- {
- q = l * (1 + s);
- }
- else
- {
- q = l + s - l * s;
- }
- p = 2 * l - q;
- r = Math.floor(hslaConvert(p, q, h + 1/3) * 256);
- g = Math.floor(hslaConvert(p, q, h) * 256);
- b = Math.floor(hslaConvert(p, q, h - 1/3) * 256);
- return [ r, g, b, a ];
- }
- function hsla2rgba_(h, s, l, a)
- {
- let c;
- c = hsla2rgba(h, s, l, a);
- return "rgba(" + c[0] + "," + c[1] + "," + c[2] + "," + c[3] + ")";
- }
Add Comment
Please, Sign In to add comment