From abd9011fa84bdc1f6ee583e387d0ec686c3dc3ab Mon Sep 17 00:00:00 2001 From: sijanec Date: Sun, 16 May 2021 16:49:09 +0200 Subject: 1.0.17.0-beta --- assets/js/colors.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 assets/js/colors.js (limited to 'assets/js/colors.js') diff --git a/assets/js/colors.js b/assets/js/colors.js new file mode 100644 index 0000000..d06861a --- /dev/null +++ b/assets/js/colors.js @@ -0,0 +1,46 @@ +/* adapted from https://git.šijanec.eu/siska/beziapp-sam-lepo */ + +function linMap(c, mn, mx) { + return c*(mx-mn)+mn; +} +function getDecimal(n) { + return (n-Math.floor(n)); +} +function mapColorPalete(c, palete) { + let poz = c*(palete.length-1); + let col1 = palete[Math.floor(poz)]; /* https://git.šijanec.eu/siska/beziapp-sam-lepo */ + let col2 = palete[Math.ceil(poz)]; /* made by siska */ + return (Math.floor(linMap(getDecimal(poz),col1[0],col2[0])).toString(16).padStart(2,0)+ + Math.floor(linMap(getDecimal(poz),col1[1],col2[1])).toString(16).padStart(2,0)+ + Math.floor(linMap(getDecimal(poz),col1[2],col2[2])).toString(16).padStart(2,0)).toUpperCase(); +} +/** + * + * Convert last 3 bytes of an integer to RGB color + * @param {integer} input_integer Integer that will be converted to RGB color + * @returns {string} Hex color code + * + */ +function intToRGB(i, palete = null) { + if (palete == null) { + var c = (i & 0x00FFFFFF) + .toString(16) + .toUpperCase(); + + return "00000".substring(0, 6 - c.length) + c; + } else return mapColorPalete((i & 0xFF) / 0xFF, palete); +} + + +/** + * + * Convert a given string to hex color + * @param {string} input_string Input string + * @returns {string} Hex RGB color + */ +function getHexColorFromString(str) { + if (urnikTheme == "privzeta") + return "#" + intToRGB(hashCode(str)); + else + return "#" + intToRGB(hashCode(str), [[38, 70, 83], [42, 157, 143], [233, 196, 106], [244, 162, 97], [231, 111, 81]]); +} -- cgit v1.2.3