diff --git a/src/animations.rs b/src/animations.rs index 31f21f8..54a7d4e 100644 --- a/src/animations.rs +++ b/src/animations.rs @@ -21,8 +21,8 @@ struct IdleShader { } impl Shader for IdleShader { - fn draw(&self, coords: &VirtualCoordinates) -> RGB8 { - Hsv::new_srgb(self.frame.wrapping_add(coords.x).wrapping_add(coords.y), 255, 255).into_rgb8() + fn draw(&self, coords: &VirtualCoordinates, frame: u8) -> RGB8 { + Hsv::new_srgb(frame.wrapping_add(coords.x).wrapping_add(coords.y), 255, 255).into_rgb8() } } @@ -84,7 +84,7 @@ struct TestShader { } impl Shader for TestShader { - fn draw(&self, coords: &VirtualCoordinates) -> RGB8 { + fn draw(&self, coords: &VirtualCoordinates, _frame: usize) -> RGB8 { match self.pattern { Pattern::Red => RGB8::new(255, 0, 0), Pattern::Green => RGB8::new(0, 255, 0), diff --git a/src/platform/smart_leds_lib.rs b/src/platform/smart_leds_lib.rs index 189232f..99c6ed5 100644 --- a/src/platform/smart_leds_lib.rs +++ b/src/platform/smart_leds_lib.rs @@ -40,7 +40,8 @@ T::Color: HardwarePixel, pixmap: StrideMapping, target: T, pixbuf: [T::Color; PIXEL_NUM], - max_mw: u32 + max_mw: u32, + frame: usize } impl Debug for SmartLedDisplay where @@ -63,7 +64,8 @@ T::Color: HardwarePixel, surfaces: Some(SurfacePool::new()), target, max_mw, - pixmap: StrideMapping::new() + pixmap: StrideMapping::new(), + frame: 0 } } } @@ -110,7 +112,7 @@ Rgb: From if idx >= PIXEL_NUM { continue; } - self.pixbuf[idx] = self.pixbuf[idx].saturating_add(shader.draw(&virt_coords)); + self.pixbuf[idx] = self.pixbuf[idx].saturating_add(shader.draw(&virt_coords, self.frame)); } }) } @@ -134,6 +136,7 @@ Rgb: From { if let Err(_) = self.target.write(brightness(self.pixbuf.iter().cloned().map(|x| { x.into() }), b)) { panic!("Could not write frame"); } + self.frame += 1; } } diff --git a/src/render.rs b/src/render.rs index c78c763..c7fd76d 100644 --- a/src/render.rs +++ b/src/render.rs @@ -9,7 +9,7 @@ use std::marker::PhantomData; use std::fmt::Debug; pub trait Shader: Send + Debug { - fn draw(&self, surface_coords: &VirtualCoordinates) -> RGB8; + fn draw(&self, surface_coords: &VirtualCoordinates, frame: usize) -> RGB8; } pub trait Surfaces: Debug {