Compare commits
No commits in common. "bbaa094f00512d3b78cb0d01ee1c55602930fcd6" and "43c53555d9bf3db9bff55d96e5d4cdb0b876b734" have entirely different histories.
bbaa094f00
...
43c53555d9
1 changed files with 26 additions and 40 deletions
62
src/main.rs
62
src/main.rs
|
@ -12,7 +12,7 @@ use std::{
|
|||
};
|
||||
|
||||
use bracket_color::prelude::{HSV, RGB};
|
||||
use clap::{Parser, Subcommand, ValueEnum};
|
||||
use clap::{Parser, Subcommand};
|
||||
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)]
|
||||
#[clap(subcommand, rename_all = "kebab-case")]
|
||||
action: Action,
|
||||
}
|
||||
|
||||
|
@ -80,23 +80,10 @@ impl From<Color> for Rgb<u8> {
|
|||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Subcommand)]
|
||||
enum Action {
|
||||
Animation {
|
||||
#[clap(value_enum)]
|
||||
animation: Animation,
|
||||
},
|
||||
Solid {
|
||||
color: Color,
|
||||
},
|
||||
Image {
|
||||
path: PathBuf,
|
||||
},
|
||||
Clear,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, ValueEnum)]
|
||||
enum Animation {
|
||||
Rainbow,
|
||||
Bling,
|
||||
Solid { color: Color },
|
||||
Image { path: PathBuf },
|
||||
Clear,
|
||||
}
|
||||
|
||||
fn bling(layout: Layout, frame: u32) -> RgbImage {
|
||||
|
@ -194,27 +181,30 @@ fn main() -> anyhow::Result<()> {
|
|||
first_strand_index: 8,
|
||||
};
|
||||
|
||||
let image = match args.action {
|
||||
match args.action {
|
||||
Action::Solid { color } => {
|
||||
RgbImage::from_pixel(layout.width_px(), layout.height_px(), color.into())
|
||||
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)?;
|
||||
}
|
||||
Action::Clear => RgbImage::new(layout.width_px(), layout.height_px()),
|
||||
Action::Image { path } => ImageReader::open(path)?
|
||||
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(),
|
||||
Action::Animation { animation } => {
|
||||
let f = match animation {
|
||||
Animation::Rainbow => rainbow,
|
||||
Animation::Bling => bling,
|
||||
};
|
||||
|
||||
.into_rgb8();
|
||||
let frame_num: u32 = rand::thread_rng().gen();
|
||||
send_frame(&socket, layout, frame_num, &image)?;
|
||||
}
|
||||
Action::Rainbow => {
|
||||
print!("{}", termion::clear::All);
|
||||
|
||||
let mut frame = 0;
|
||||
loop {
|
||||
let start = Instant::now();
|
||||
let image = f(layout, frame);
|
||||
for frame in 0.. {
|
||||
let image = rainbow(layout, frame);
|
||||
|
||||
print_image(&image);
|
||||
|
||||
|
@ -222,13 +212,9 @@ 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