Commit 978fcfb6 authored by gj4210's avatar gj4210 👽
Browse files

ADD: colorutils to handle hashed colors consistently across frontend

parent 7ca4635d
// https://gist.github.com/0x263b/2bdd90886c2036a1ad5bcf06d6e6fb37
// (modified)
String.prototype.toHSL = function(opts) {
let h, s, l;
opts = opts || {};
opts.hue = opts.hue || [0, 360];
opts.sat = opts.sat || [75, 100];
opts.lit = opts.lit || [40, 60];
let range = function(hash, min, max) {
let diff = max - min;
let x = ((hash % diff) + diff) % diff;
return x + min;
}
let hash = 0;
if (this.length === 0) return hash;
for (let i = 0; i < this.length; i++) {
hash = this.charCodeAt(i) + ((hash << 5) - hash);
hash = hash & hash;
}
h = range(hash, opts.hue[0], opts.hue[1]);
s = range(hash, opts.sat[0], opts.sat[1]);
l = range(hash, opts.lit[0], opts.lit[1]);
return `hsl(${h}, ${s}%, ${l}%)`;
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment