Skip to content

Instantly share code, notes, and snippets.

@metavoid
Created February 10, 2019 21:39
Show Gist options
  • Select an option

  • Save metavoid/12dd719cd661608fc124dcdc37217ae4 to your computer and use it in GitHub Desktop.

Select an option

Save metavoid/12dd719cd661608fc124dcdc37217ae4 to your computer and use it in GitHub Desktop.
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 + ")";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment