Skip to content

Instantly share code, notes, and snippets.

@genesisneo
Created February 11, 2021 17:57
Show Gist options
  • Save genesisneo/72fae1862f49679c51c40359a8c277ae to your computer and use it in GitHub Desktop.
Save genesisneo/72fae1862f49679c51c40359a8c277ae to your computer and use it in GitHub Desktop.
Randomly generate angle and 2 set of colors for gradient background.
/*
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