summaryrefslogtreecommitdiffstats
path: root/assets/js/colors.js
blob: d06861a7aa3368f1b93ec2d23f016e93da0053f5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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]]);
}