Last active
March 21, 2020 04:47
-
-
Save alexcmgit/ba977cbcec0ee54e99bd03d837651fed to your computer and use it in GitHub Desktop.
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
function generateRandomColor(userConfig = {}) { | |
const defaultConfig = { | |
r: [0, 255], | |
g: [0, 255], | |
b: [0, 255], | |
a: [1, 1], | |
} | |
const config = Object.assign({}, defaultConfig, userConfig); | |
let { r, g, b, a } = config; | |
let [minR, maxR] = r; | |
let [minG, maxG] = g; | |
let [minB, maxB] = b; | |
let [minA, maxA] = a; | |
maxA *= 1000; | |
minA *= 1000; | |
r = randomIntFromInterval(minR, maxR); | |
g = randomIntFromInterval(minG, maxG); | |
b = randomIntFromInterval(minB, maxB); | |
a = randomIntFromInterval(minA, maxA) / 1000; | |
return `rgba(${r}, ${g}, ${b}, ${a})`; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment