feat: allow multiple animations

This commit is contained in:
Xiretza 2022-06-17 22:00:02 +02:00
parent 75d1b93f7e
commit 65381889ed

View file

@ -12,7 +12,7 @@ use std::{
}; };
use bracket_color::prelude::{HSV, RGB}; use bracket_color::prelude::{HSV, RGB};
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand, ValueEnum};
use image::{imageops::FilterType, io::Reader as ImageReader, Pixel, Rgb, RgbImage}; use image::{imageops::FilterType, io::Reader as ImageReader, Pixel, Rgb, RgbImage};
use rand::Rng; use rand::Rng;
@ -80,12 +80,25 @@ impl From<Color> for Rgb<u8> {
#[derive(Clone, Debug, PartialEq, Eq, Subcommand)] #[derive(Clone, Debug, PartialEq, Eq, Subcommand)]
enum Action { enum Action {
Rainbow, Animation {
Solid { color: Color }, #[clap(value_enum)]
Image { path: PathBuf }, animation: Animation,
},
Solid {
color: Color,
},
Image {
path: PathBuf,
},
Clear, Clear,
} }
#[derive(Clone, Debug, PartialEq, Eq, ValueEnum)]
enum Animation {
Rainbow,
Bling,
}
fn bling(layout: Layout, frame: u32) -> RgbImage { fn bling(layout: Layout, frame: u32) -> RgbImage {
#![allow( #![allow(
clippy::cast_precision_loss, clippy::cast_precision_loss,
@ -190,13 +203,18 @@ fn main() -> anyhow::Result<()> {
.decode()? .decode()?
.resize_to_fill(layout.width_px(), layout.height_px(), FilterType::Gaussian) .resize_to_fill(layout.width_px(), layout.height_px(), FilterType::Gaussian)
.into_rgb8(), .into_rgb8(),
Action::Rainbow => { Action::Animation { animation } => {
let f = match animation {
Animation::Rainbow => rainbow,
Animation::Bling => bling,
};
print!("{}", termion::clear::All); print!("{}", termion::clear::All);
let mut frame = 0; let mut frame = 0;
loop { loop {
let start = Instant::now(); let start = Instant::now();
let image = rainbow(layout, frame); let image = f(layout, frame);
print_image(&image); print_image(&image);