Created
August 20, 2018 08:03
-
-
Save frankfaustino/8aba83f96d48fb4c2a71d0fc2a1fdd18 to your computer and use it in GitHub Desktop.
Generate Color Gradient
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
generateColor = (start, end, h, row) => { | |
const scale = row / h | |
const r = Math.round( | |
Math.min(255, Math.max(0, start.red + scale * (end.red - start.red))) | |
) | |
const g = Math.round( | |
Math.min(255, Math.max(0, start.green + scale * (end.green - start.green))) | |
) | |
const b = Math.round( | |
Math.min(255, Math.max(0, start.blue + scale * (end.blue - start.blue))) | |
) | |
return `rgb(${r}, ${g}, ${b})` | |
} | |
const primaryColor = { | |
red: 232, | |
green: 134, | |
blue: 60 | |
} | |
const secondaryColor = { | |
red: 23, | |
green: 121, | |
blue: 195 | |
} | |
const height = 1000 | |
const gradient = [] | |
for (let i = 0; i < height; i++) { | |
gradient.push(generateColor(primaryColor, secondaryColor, height, i)) | |
} | |
console.log(gradient) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment