From 966d3027e3e46f0a255e843532fce2dd16c40f20 Mon Sep 17 00:00:00 2001 From: Xiretza Date: Fri, 24 Jun 2022 20:45:57 +0200 Subject: [PATCH] feat: add strobe animation --- src/main.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main.rs b/src/main.rs index 01699f9..3de59c4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -92,6 +92,7 @@ enum Action { enum Animation { Rainbow, Bling, + Strobe, } 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) { let _hide = termion::cursor::HideCursor::from(stdout()); @@ -237,6 +254,7 @@ fn main() -> anyhow::Result<()> { match animation { Animation::Rainbow => rainbow, Animation::Bling => bling, + Animation::Strobe => strobe, }, )?; }