update app_modules.js
This commit is contained in:
@@ -30,26 +30,46 @@ const debounce = (callback, wait) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
String.prototype.toHex = function() {
|
String.prototype.toHex = function() {
|
||||||
var s = this + "0123456789" + this;
|
const hueStep = 15; // step in degrees
|
||||||
var colors = [
|
const saturation = 70; // %
|
||||||
"#ff0000",
|
const lightness = 50; // %
|
||||||
"#ff00ff",
|
|
||||||
"#00ff00",
|
// Simple hash function
|
||||||
"#0000ff",
|
let hash = 0;
|
||||||
"#00ffff",
|
for (let i = 0; i < this.length; i++) {
|
||||||
"#000000",
|
hash = (hash * 31 + this.charCodeAt(i)) >>> 0;
|
||||||
];
|
}
|
||||||
var color =
|
|
||||||
(((((s.charCodeAt(1) * s.charCodeAt(2)) / s.charCodeAt(s.length - 1)) *
|
// Calculate hue in steps
|
||||||
s.charCodeAt(s.length - 2)) /
|
const hue = (hash * hueStep) % 360;
|
||||||
s.charCodeAt(s.length - 2)) *
|
|
||||||
s.charCodeAt(s.length - 3)) /
|
// Convert HSL to hex
|
||||||
s.charCodeAt(s.length - 3);
|
function hslToHex(h, s, l) {
|
||||||
var cid = colors[Math.round(color) % colors.length];
|
s /= 100;
|
||||||
console.log(color, cid, colors);
|
l /= 100;
|
||||||
return cid;
|
const c = (1 - Math.abs(2 * l - 1)) * s;
|
||||||
|
const x = c * (1 - Math.abs(((h / 60) % 2) - 1));
|
||||||
|
const m = l - c / 2;
|
||||||
|
let r = 0, g = 0, b = 0;
|
||||||
|
|
||||||
|
if (h >= 0 && h < 60) [r, g, b] = [c, x, 0];
|
||||||
|
else if (h >= 60 && h < 120) [r, g, b] = [x, c, 0];
|
||||||
|
else if (h >= 120 && h < 180) [r, g, b] = [0, c, x];
|
||||||
|
else if (h >= 180 && h < 240) [r, g, b] = [0, x, c];
|
||||||
|
else if (h >= 240 && h < 300) [r, g, b] = [x, 0, c];
|
||||||
|
else [r, g, b] = [c, 0, x];
|
||||||
|
|
||||||
|
r = Math.round((r + m) * 255);
|
||||||
|
g = Math.round((g + m) * 255);
|
||||||
|
b = Math.round((b + m) * 255);
|
||||||
|
|
||||||
|
return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return hslToHex(hue, saturation, lightness);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
function stringToColour(str) {
|
function stringToColour(str) {
|
||||||
return str.toHex();
|
return str.toHex();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user