Created
November 17, 2019 00:36
-
-
Save CoralSilver/5d952a6802ed2c320940a4e8e8e5e0da to your computer and use it in GitHub Desktop.
function to randomly generate a color with a set opacity
This file contains 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
// default shade value of 200, increment up to 255 for brighter colors, deincrement down to 0 for darker colors | |
const generateRandomRGB = (shade = 200, alpha = 1) => { | |
shade = (shade >= 0 && shade <= 255) ? shade : 255; | |
const generateRandomColor = () => { | |
return Math.ceil(Math.random() * shade); | |
} | |
const red = generateRandomColor(shade); | |
const green = generateRandomColor(shade); | |
const blue = generateRandomColor(shade); | |
return `rgba(${red}, ${green}, ${blue}, ${alpha})`; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment