Skip to content

Instantly share code, notes, and snippets.

@alexrintt
Last active March 21, 2020 04:47
Show Gist options
  • Save alexrintt/ba977cbcec0ee54e99bd03d837651fed to your computer and use it in GitHub Desktop.
Save alexrintt/ba977cbcec0ee54e99bd03d837651fed to your computer and use it in GitHub Desktop.
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