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 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,12 +203,17 @@ 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 image = rainbow(layout, frame);
|
let image = f(layout, frame);
|
||||||
|
|
||||||
print_image(&image);
|
print_image(&image);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue