From 1bc267461afb559a70bc242c94854fb2735941bb Mon Sep 17 00:00:00 2001 From: Nicolas <> Date: Sat, 2 Apr 2022 17:25:35 +0200 Subject: [PATCH] Add fill modes --- src/fill/level.rs | 16 ++++++++++++++++ src/fill/mod.rs | 35 +++++++++++++++++++++++++++++++++++ src/main.rs | 5 +++++ 3 files changed, 56 insertions(+) create mode 100644 src/fill/level.rs create mode 100644 src/fill/mod.rs diff --git a/src/fill/level.rs b/src/fill/level.rs new file mode 100644 index 0000000..04da362 --- /dev/null +++ b/src/fill/level.rs @@ -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 + } +} \ No newline at end of file diff --git a/src/fill/mod.rs b/src/fill/mod.rs new file mode 100644 index 0000000..2a6ecf9 --- /dev/null +++ b/src/fill/mod.rs @@ -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, 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 { + match mode { + FillModeEnum::Circle => todo!(), + FillModeEnum::Level => Box::new(LevelFillMode::new()), + FillModeEnum::Stripe => todo!() + } +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 2004c2c..455264d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,14 +1,19 @@ use clap::Parser; use rand::rngs::OsRng; use crate::char::CharSampler; +use crate::fill::FillModeEnum; use crate::pallet::{choose_pallet, create_pallet, PalletEnum}; mod pallet; mod char; +mod fill; +mod vec; #[derive(Parser)] #[clap(author = "Rico Riedel", version = "0.1.0", about = "Wipe your terminal with a random animation.")] struct Args { + #[clap(short, long, help = "Add fill mode", arg_enum)] + fill: Vec, #[clap(short, long, help = "Add color pallet", arg_enum)] pallet: Vec, #[clap(long, default_value = ".-+%#", help = "Set chars")]