Compare commits
3 commits
43c53555d9
...
bbaa094f00
Author | SHA1 | Date | |
---|---|---|---|
bbaa094f00 | |||
65381889ed | |||
75d1b93f7e |
1 changed files with 40 additions and 26 deletions
66
src/main.rs
66
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;
|
||||
|
||||
|
@ -35,7 +35,7 @@ struct Args {
|
|||
remote_addr: SocketAddr,
|
||||
|
||||
/// The action to perform
|
||||
#[clap(subcommand, rename_all = "kebab-case")]
|
||||
#[clap(subcommand)]
|
||||
action: Action,
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
@ -181,30 +194,27 @@ fn main() -> anyhow::Result<()> {
|
|||
first_strand_index: 8,
|
||||
};
|
||||
|
||||
match args.action {
|
||||
let image = match args.action {
|
||||
Action::Solid { color } => {
|
||||
let image = RgbImage::from_pixel(layout.width_px(), layout.height_px(), color.into());
|
||||
let frame_num: u32 = rand::thread_rng().gen();
|
||||
send_frame(&socket, layout, frame_num, &image)?;
|
||||
RgbImage::from_pixel(layout.width_px(), layout.height_px(), color.into())
|
||||
}
|
||||
Action::Clear => {
|
||||
let image = RgbImage::new(layout.width_px(), layout.height_px());
|
||||
let frame_num: u32 = rand::thread_rng().gen();
|
||||
send_frame(&socket, layout, frame_num, &image)?;
|
||||
}
|
||||
Action::Image { path } => {
|
||||
let image = ImageReader::open(path)?
|
||||
.decode()?
|
||||
.resize_to_fill(layout.width_px(), layout.height_px(), FilterType::Gaussian)
|
||||
.into_rgb8();
|
||||
let frame_num: u32 = rand::thread_rng().gen();
|
||||
send_frame(&socket, layout, frame_num, &image)?;
|
||||
}
|
||||
Action::Rainbow => {
|
||||
Action::Clear => RgbImage::new(layout.width_px(), layout.height_px()),
|
||||
Action::Image { path } => ImageReader::open(path)?
|
||||
.decode()?
|
||||
.resize_to_fill(layout.width_px(), layout.height_px(), FilterType::Gaussian)
|
||||
.into_rgb8(),
|
||||
Action::Animation { animation } => {
|
||||
let f = match animation {
|
||||
Animation::Rainbow => rainbow,
|
||||
Animation::Bling => bling,
|
||||
};
|
||||
|
||||
print!("{}", termion::clear::All);
|
||||
|
||||
for frame in 0.. {
|
||||
let image = rainbow(layout, frame);
|
||||
let mut frame = 0;
|
||||
loop {
|
||||
let start = Instant::now();
|
||||
let image = f(layout, frame);
|
||||
|
||||
print_image(&image);
|
||||
|
||||
|
@ -212,9 +222,13 @@ fn main() -> anyhow::Result<()> {
|
|||
send_frame(&socket, layout, frame_num, &image)?;
|
||||
|
||||
sleep(Duration::from_millis(16));
|
||||
frame += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let frame_num: u32 = rand::thread_rng().gen();
|
||||
send_frame(&socket, layout, frame_num, &image)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue