metavoid
2/10/2019 - 9:39 PM

Color utils

Color utils

//Color utils

	function getRandomColor() {
		for (var a = "0123456789ABCDEF".split(""), b = "#", c = 0; 6 > c; c++)
			b += a[Math.floor(16 * Math.random())];
		return b
	}

	function hexToRGB(hex, alpha) {
		let r = parseInt(hex.slice(1, 3), 16),
			g = parseInt(hex.slice(3, 5), 16),
			b = parseInt(hex.slice(5, 7), 16);

		if (alpha) {
			return "rgba(" + r + ", " + g + ", " + b + ", " + alpha + ")";
		} else {
			return "rgb(" + r + ", " + g + ", " + b + ")";
		}
	}