feat: add strobe animation

This commit is contained in:
Xiretza 2022-06-24 20:45:57 +02:00
parent 35a3319e7f
commit 966d3027e3

View file

@ -92,6 +92,7 @@ enum Action {
enum Animation { enum Animation {
Rainbow, Rainbow,
Bling, Bling,
Strobe,
} }
fn bling(layout: Layout, frame: u32) -> RgbImage { fn bling(layout: Layout, frame: u32) -> RgbImage {
@ -160,6 +161,22 @@ fn rainbow(layout: Layout, frame: u32) -> RgbImage {
}) })
} }
fn strobe(layout: Layout, frame: u32) -> RgbImage {
let w = layout.width_px();
let h = layout.height_px();
let brightness = 120;
let period = 15;
RgbImage::from_fn(w, h, |_, _| {
if frame % period < period / 2 {
Rgb([brightness; 3])
} else {
Rgb([0, 0, 0])
}
})
}
fn print_image(image: &RgbImage) { fn print_image(image: &RgbImage) {
let _hide = termion::cursor::HideCursor::from(stdout()); let _hide = termion::cursor::HideCursor::from(stdout());
@ -237,6 +254,7 @@ fn main() -> anyhow::Result<()> {
match animation { match animation {
Animation::Rainbow => rainbow, Animation::Rainbow => rainbow,
Animation::Bling => bling, Animation::Bling => bling,
Animation::Strobe => strobe,
}, },
)?; )?;
} }