Created
February 11, 2021 17:57
-
-
Save genesisneo/72fae1862f49679c51c40359a8c277ae to your computer and use it in GitHub Desktop.
Randomly generate angle and 2 set of colors for gradient background.
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
/* | |
Examples: | |
gradientGenerator() = { angle: 128, colorOne: "#e29482", colorTwo: "#c98d47" } | |
*/ | |
const gradientGenerator = () => { | |
const hexValues = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e']; | |
const generateGradient = (color) => { | |
for (let i = 0; i < 6; i++) { | |
const x = Math.round(Math.random() * 14); | |
const y = hexValues[x]; | |
color += y; | |
} | |
return color; | |
} | |
const angle = Math.round(Math.random() * 360); | |
const colorOne = generateGradient('#'); | |
const colorTwo = generateGradient('#'); | |
return { angle, colorOne, colorTwo } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment