From 491109885d691c4831f6caa12320918110af55c0 Mon Sep 17 00:00:00 2001 From: Tangent 128 Date: Sat, 16 Mar 2019 00:26:42 -0400 Subject: [PATCH] Fix glitch from wrapping. --- hello_gradient/src/main.rs | 43 ++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/hello_gradient/src/main.rs b/hello_gradient/src/main.rs index e5d35a7..49913b5 100644 --- a/hello_gradient/src/main.rs +++ b/hello_gradient/src/main.rs @@ -1,7 +1,6 @@ #![no_std] #![no_main] -use core::num::Wrapping; use lights::{ gamma::GammaCorrector, PixelIterator, @@ -17,30 +16,28 @@ use lights_hal::{boot, delay, entry}; fn main() -> ! { let mut lights = GammaCorrector(boot()); - let mut t = Wrapping(0u8); + let red = Rgb(150, 0, 0); + let yellow = Rgb(150, 150, 0); + let green = Rgb(0, 150, 0); + let teal = Rgb(0, 75, 150); + let purple = Rgb(75, 0, 150); + + let mut gradient = (0..16u8).map( + |x| blend(red, yellow, gray(x * 16)) + ).chain((0..16u8).map( + |x| blend(yellow, green, gray(x * 16)) + )).chain((0..16u8).map( + |x| blend(green, teal, gray(x * 16)) + )).chain((0..16u8).map( + |x| blend(teal, purple, gray(x * 16)) + )).chain((0..16u8).map( + |x| blend(purple, red, gray(x * 16)) + )).cycle(); + loop { - t += Wrapping(1); - - let red = Rgb(150, 0, 0); - let yellow = Rgb(150, 150, 0); - let green = Rgb(0, 150, 0); - let teal = Rgb(0, 75, 150); - let purple = Rgb(75, 0, 150); - - (0..16u8).map( - |x| blend(red, yellow, gray(x * 16)) - ).chain((0..16u8).map( - |x| blend(yellow, green, gray(x * 16)) - )).chain((0..16u8).map( - |x| blend(green, teal, gray(x * 16)) - )).chain((0..16u8).map( - |x| blend(teal, purple, gray(x * 16)) - )).chain((0..16u8).map( - |x| blend(purple, red, gray(x * 16)) - )) - .cycle().skip(t.0 as usize).take(20) - .render_to(&mut lights); + gradient.clone().take(20).render_to(&mut lights); + gradient.next(); delay(1_000_000); } }