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