Add fill modes

This commit is contained in:
Nicolas 2022-04-02 17:25:35 +02:00
parent 57bbb6e9a7
commit 1bc267461a
3 changed files with 56 additions and 0 deletions

16
src/fill/level.rs Normal file
View File

@ -0,0 +1,16 @@
use crate::fill::FillMode;
use crate::vec::Vector;
pub struct LevelFillMode;
impl LevelFillMode {
pub fn new() -> Self {
Self { }
}
}
impl FillMode for LevelFillMode {
fn sample(&self, level: f32, _: Vector) -> f32 {
level
}
}

35
src/fill/mod.rs Normal file
View File

@ -0,0 +1,35 @@
mod level;
use clap::ArgEnum;
use rand::prelude::IteratorRandom;
use rand::Rng;
use crate::fill::level::LevelFillMode;
use crate::vec::Vector;
pub trait FillMode {
fn sample(&self, level: f32, pos: Vector) -> f32;
}
#[derive(Copy, Clone, ArgEnum)]
pub enum FillModeEnum {
Circle,
Level,
Stripe
}
pub fn choose_fill_mode(mut options: Vec<FillModeEnum>, rng: &mut impl Rng) -> FillModeEnum {
if options.is_empty() {
options.push(FillModeEnum::Circle);
options.push(FillModeEnum::Level);
options.push(FillModeEnum::Stripe);
}
options.into_iter().choose(rng).unwrap()
}
pub fn create_fill_mode(mode: FillModeEnum, _: Vector) -> Box<dyn FillMode> {
match mode {
FillModeEnum::Circle => todo!(),
FillModeEnum::Level => Box::new(LevelFillMode::new()),
FillModeEnum::Stripe => todo!()
}
}

View File

@ -1,14 +1,19 @@
use clap::Parser; use clap::Parser;
use rand::rngs::OsRng; use rand::rngs::OsRng;
use crate::char::CharSampler; use crate::char::CharSampler;
use crate::fill::FillModeEnum;
use crate::pallet::{choose_pallet, create_pallet, PalletEnum}; use crate::pallet::{choose_pallet, create_pallet, PalletEnum};
mod pallet; mod pallet;
mod char; mod char;
mod fill;
mod vec;
#[derive(Parser)] #[derive(Parser)]
#[clap(author = "Rico Riedel", version = "0.1.0", about = "Wipe your terminal with a random animation.")] #[clap(author = "Rico Riedel", version = "0.1.0", about = "Wipe your terminal with a random animation.")]
struct Args { struct Args {
#[clap(short, long, help = "Add fill mode", arg_enum)]
fill: Vec<FillModeEnum>,
#[clap(short, long, help = "Add color pallet", arg_enum)] #[clap(short, long, help = "Add color pallet", arg_enum)]
pallet: Vec<PalletEnum>, pallet: Vec<PalletEnum>,
#[clap(long, default_value = ".-+%#", help = "Set chars")] #[clap(long, default_value = ".-+%#", help = "Set chars")]