summaryrefslogtreecommitdiffstats
path: root/assets/js/colors.js
diff options
context:
space:
mode:
authorsijanec <anton@sijanec.eu>2021-05-16 16:49:09 +0200
committersijanec <anton@sijanec.eu>2021-05-16 16:49:09 +0200
commitabd9011fa84bdc1f6ee583e387d0ec686c3dc3ab (patch)
tree297222608598dae2478c79f4e82b655c6c497292 /assets/js/colors.js
parentMerge branch 'master' into dev (diff)
downloadbeziapp-abd9011fa84bdc1f6ee583e387d0ec686c3dc3ab.tar
beziapp-abd9011fa84bdc1f6ee583e387d0ec686c3dc3ab.tar.gz
beziapp-abd9011fa84bdc1f6ee583e387d0ec686c3dc3ab.tar.bz2
beziapp-abd9011fa84bdc1f6ee583e387d0ec686c3dc3ab.tar.lz
beziapp-abd9011fa84bdc1f6ee583e387d0ec686c3dc3ab.tar.xz
beziapp-abd9011fa84bdc1f6ee583e387d0ec686c3dc3ab.tar.zst
beziapp-abd9011fa84bdc1f6ee583e387d0ec686c3dc3ab.zip
Diffstat (limited to 'assets/js/colors.js')
-rw-r--r--assets/js/colors.js46
1 files changed, 46 insertions, 0 deletions
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]]);
+}