feat: allow multiple animations
This commit is contained in:
parent
3c431ccac3
commit
3d49b36f33
1 changed files with 24 additions and 6 deletions
30
src/main.rs
30
src/main.rs
|
@ -12,7 +12,7 @@ use std::{
|
|||
};
|
||||
|
||||
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 rand::Rng;
|
||||
|
||||
|
@ -80,12 +80,25 @@ impl From<Color> for Rgb<u8> {
|
|||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Subcommand)]
|
||||
enum Action {
|
||||
Rainbow,
|
||||
Solid { color: Color },
|
||||
Image { path: PathBuf },
|
||||
Animation {
|
||||
#[clap(value_enum)]
|
||||
animation: Animation,
|
||||
},
|
||||
Solid {
|
||||
color: Color,
|
||||
},
|
||||
Image {
|
||||
path: PathBuf,
|
||||
},
|
||||
Clear,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, ValueEnum)]
|
||||
enum Animation {
|
||||
Rainbow,
|
||||
Bling,
|
||||
}
|
||||
|
||||
fn bling(layout: Layout, frame: u32) -> RgbImage {
|
||||
#![allow(
|
||||
clippy::cast_precision_loss,
|
||||
|
@ -190,12 +203,17 @@ fn main() -> anyhow::Result<()> {
|
|||
.decode()?
|
||||
.resize_to_fill(layout.width_px(), layout.height_px(), FilterType::Gaussian)
|
||||
.into_rgb8(),
|
||||
Action::Rainbow => {
|
||||
Action::Animation { animation } => {
|
||||
let f = match animation {
|
||||
Animation::Rainbow => rainbow,
|
||||
Animation::Bling => bling,
|
||||
};
|
||||
|
||||
print!("{}", termion::clear::All);
|
||||
|
||||
let mut frame = 0;
|
||||
loop {
|
||||
let image = rainbow(layout, frame);
|
||||
let image = f(layout, frame);
|
||||
|
||||
print_image(&image);
|
||||
|
||||
|
|
Loading…
Reference in a new issue