Last active
August 1, 2023 10:01
-
-
Save peacefixation/5eeb6e992a012ea2f42cd5419df65ea7 to your computer and use it in GitHub Desktop.
Linear interpolate RGB colors
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
// interpolate between colors { r, g, b } where 0 < t < 1 | |
// when assigning a color for a number in a range larger than 0-1, scale the number to the 0-1 range first | |
function lerpRGB(color1, color2, t) { | |
let color = {}; | |
color.r = color1.r + ((color2.r - color1.r) * t); | |
color.g = color1.g + ((color2.g - color1.g) * t); | |
color.b = color1.b + ((color2.b - color1.b) * t); | |
return color; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment