Created
February 10, 2019 21:39
-
-
Save metavoid/12dd719cd661608fc124dcdc37217ae4 to your computer and use it in GitHub Desktop.
Color utils
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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