Created
February 27, 2023 14:37
-
-
Save juliarose/f729699f672bb366b81da074c7e34064 to your computer and use it in GitHub Desktop.
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
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