Add linear_gradient() helper

This commit is contained in:
Tangent 2019-03-17 01:04:03 -04:00
parent 491109885d
commit 51e5506cd8
2 changed files with 14 additions and 12 deletions
lights/src

View file

@ -60,3 +60,7 @@ pub const fn gray(gray: u8) -> Rgb {
pub fn blend(a: Rgb, b: Rgb, mix: Rgb) -> Rgb {
(a * Rgb(255 - mix.0, 255 - mix.1, 255 - mix.2)) + (b * mix)
}
pub fn linear_gradient(from: Rgb, to: Rgb, steps: usize) -> impl Iterator<Item = Rgb> + Clone {
(0..steps).map(move |x| blend(from, to, gray((x * 255 / steps) as u8)))
}