Skip to content

Instantly share code, notes, and snippets.

@peacefixation
Last active August 1, 2023 10:01
Show Gist options
  • Save peacefixation/5eeb6e992a012ea2f42cd5419df65ea7 to your computer and use it in GitHub Desktop.
Save peacefixation/5eeb6e992a012ea2f42cd5419df65ea7 to your computer and use it in GitHub Desktop.
Linear interpolate RGB colors
// 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