Skip to content

Instantly share code, notes, and snippets.

@juliarose
Created February 27, 2023 14:37
Show Gist options
  • Save juliarose/f729699f672bb366b81da074c7e34064 to your computer and use it in GitHub Desktop.
Save juliarose/f729699f672bb366b81da074c7e34064 to your computer and use it in GitHub Desktop.
type Color = [u8; 3];
/// Blends two colors.
fn blend_colors(a: Color, b: Color, amount: f32) -> String {
a.into_iter().zip(b)
.map(|(a, b)| {
let a = a as f32 * (1.0 - amount);
let b = b as f32 * amount;
let sum = (a + b) as u8;
format!("{:02X}", sum)
})
.collect::<Vec<_>>()
.join("")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment