diff --git a/src/char.rs b/src/char.rs index 963a744..bbcda06 100644 --- a/src/char.rs +++ b/src/char.rs @@ -1,12 +1,18 @@ +/// Used to get a character with a given brightness. pub struct CharSampler { chars: String } impl CharSampler { + /// # Arguments + /// * `chars`: The characters ordered by brightness. pub fn new(chars: String) -> Self { Self { chars } } + /// Gets a character with the given brightness. + /// # Arguments + /// * `level`: `0 <= level` and `level < 1` pub fn sample(&self, level: f32) -> char { let pos = level * self.chars.chars().count() as f32; let index = pos as usize; diff --git a/src/fill/mod.rs b/src/fill/mod.rs index 2a6ecf9..83505f3 100644 --- a/src/fill/mod.rs +++ b/src/fill/mod.rs @@ -6,7 +6,14 @@ use rand::Rng; use crate::fill::level::LevelFillMode; use crate::vec::Vector; +/// Used to choose the colors of characters. pub trait FillMode { + /// Gets the color for this character. + /// # Arguments + /// * `level`: + /// * `pos`: + /// + /// returns: f32 fn sample(&self, level: f32, pos: Vector) -> f32; } diff --git a/src/pallet.rs b/src/pallet.rs index b7b10e3..ff5c58e 100644 --- a/src/pallet.rs +++ b/src/pallet.rs @@ -4,6 +4,7 @@ use rand::prelude::IteratorRandom; use rand::Rng; use clap::ArgEnum; +/// A collection of colors. pub struct Pallet { values: Vec } @@ -45,6 +46,9 @@ impl Pallet { Pallet::new(vec![Magenta, Blue, Green, Yellow, Red]) } + /// Gets a color for the given fill. + /// # Arguments + /// * `fill`: `0 <= fill` and `fill < 1` pub fn sample(&self, fill: f32) -> Color { let pos = self.values.len() as f32 * fill; let index = pos as usize; @@ -65,6 +69,12 @@ pub enum PalletEnum { Rainbow } + +/// Chooses a random color pallet. +/// If none is provided, a random one of all available is chosen. +/// # Arguments +/// * `options`: A list of all options. +/// * `rng`: The number generator. pub fn choose_pallet(mut options: Vec, rng: &mut impl Rng) -> PalletEnum { if options.is_empty() { options.push(PalletEnum::Red); @@ -79,6 +89,9 @@ pub fn choose_pallet(mut options: Vec, rng: &mut impl Rng) -> Pallet options.into_iter().choose(rng).unwrap() } +/// Creates the requested pallet. +/// # Arguments +/// * `pallet`: The pallet type. pub fn create_pallet(pallet: PalletEnum) -> Pallet { match pallet { PalletEnum::Red => Pallet::red(), diff --git a/src/vec.rs b/src/vec.rs index 2a0170b..237f74c 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -1,3 +1,4 @@ +/// A vector with a x and y axis. #[derive(Copy, Clone)] pub struct Vector { pub x: f32, @@ -9,6 +10,10 @@ impl Vector { Self { x, y } } + /// Creates a vector with the on screen coordinates based on the terminal coordinates. + /// # Arguments + /// * `x`: The x axis of the terminal character. + /// * `y`: The y axis of the terminal character. pub fn from_terminal(x: usize, y: usize) -> Self { Vector::new(x as f32, y as f32 * 2.0) }