mirror of
https://github.com/ricoriedel/wipe.git
synced 2024-11-18 05:56:40 +00:00
Add char.rs
This commit is contained in:
parent
aed1f6d58e
commit
c193d5897a
16
src/char.rs
Normal file
16
src/char.rs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
pub struct CharSampler {
|
||||||
|
chars: String
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CharSampler {
|
||||||
|
pub fn new(chars: String) -> Self {
|
||||||
|
Self { chars }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn sample(&self, level: f32) -> char {
|
||||||
|
let pos = level * self.chars.chars().count() as f32;
|
||||||
|
let index = pos as usize;
|
||||||
|
|
||||||
|
self.chars.chars().nth(index).unwrap()
|
||||||
|
}
|
||||||
|
}
|
@ -1,20 +1,26 @@
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use rand::rngs::OsRng;
|
use rand::rngs::OsRng;
|
||||||
|
use crate::char::CharSampler;
|
||||||
use crate::pallet::{choose_pallet, create_pallet, PalletEnum};
|
use crate::pallet::{choose_pallet, create_pallet, PalletEnum};
|
||||||
|
|
||||||
mod pallet;
|
mod pallet;
|
||||||
|
mod char;
|
||||||
|
|
||||||
#[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 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")]
|
||||||
|
chars: String
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
let rng = &mut OsRng::default();
|
let rng = &mut OsRng::default();
|
||||||
|
|
||||||
|
let chars = CharSampler::new(args.chars);
|
||||||
|
|
||||||
let pallet_key = choose_pallet(args.pallet, rng);
|
let pallet_key = choose_pallet(args.pallet, rng);
|
||||||
let pallet = create_pallet(pallet_key);
|
let pallet = create_pallet(pallet_key);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user