add some some color-manipulation tools

This commit is contained in:
Tangent Wantwight 2019-11-23 18:52:43 -05:00
parent d4e2606890
commit d53b000bb3
1 changed files with 8 additions and 2 deletions

View File

@ -61,6 +61,12 @@ 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)))
#[inline]
pub fn blend_steps(from: Rgb, to: Rgb, steps: usize, x: usize) -> Rgb {
blend(from, to, gray((x * 255 / steps) as u8))
}
#[inline]
pub fn linear_gradient(from: Rgb, to: Rgb, steps: usize) -> impl Iterator<Item = Rgb> + DoubleEndedIterator + Clone {
(0..steps).map(move |x| blend_steps(from, to, steps, x))
}