mirror of
https://github.com/ricoriedel/wipe.git
synced 2024-11-23 00:16:38 +00:00
Add comments
This commit is contained in:
parent
1bc267461a
commit
0e0f012810
@ -1,12 +1,18 @@
|
|||||||
|
/// Used to get a character with a given brightness.
|
||||||
pub struct CharSampler {
|
pub struct CharSampler {
|
||||||
chars: String
|
chars: String
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CharSampler {
|
impl CharSampler {
|
||||||
|
/// # Arguments
|
||||||
|
/// * `chars`: The characters ordered by brightness.
|
||||||
pub fn new(chars: String) -> Self {
|
pub fn new(chars: String) -> Self {
|
||||||
Self { chars }
|
Self { chars }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Gets a character with the given brightness.
|
||||||
|
/// # Arguments
|
||||||
|
/// * `level`: `0 <= level` and `level < 1`
|
||||||
pub fn sample(&self, level: f32) -> char {
|
pub fn sample(&self, level: f32) -> char {
|
||||||
let pos = level * self.chars.chars().count() as f32;
|
let pos = level * self.chars.chars().count() as f32;
|
||||||
let index = pos as usize;
|
let index = pos as usize;
|
||||||
|
@ -6,7 +6,14 @@ use rand::Rng;
|
|||||||
use crate::fill::level::LevelFillMode;
|
use crate::fill::level::LevelFillMode;
|
||||||
use crate::vec::Vector;
|
use crate::vec::Vector;
|
||||||
|
|
||||||
|
/// Used to choose the colors of characters.
|
||||||
pub trait FillMode {
|
pub trait FillMode {
|
||||||
|
/// Gets the color for this character.
|
||||||
|
/// # Arguments
|
||||||
|
/// * `level`:
|
||||||
|
/// * `pos`:
|
||||||
|
///
|
||||||
|
/// returns: f32
|
||||||
fn sample(&self, level: f32, pos: Vector) -> f32;
|
fn sample(&self, level: f32, pos: Vector) -> f32;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ use rand::prelude::IteratorRandom;
|
|||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use clap::ArgEnum;
|
use clap::ArgEnum;
|
||||||
|
|
||||||
|
/// A collection of colors.
|
||||||
pub struct Pallet {
|
pub struct Pallet {
|
||||||
values: Vec<Color>
|
values: Vec<Color>
|
||||||
}
|
}
|
||||||
@ -45,6 +46,9 @@ impl Pallet {
|
|||||||
Pallet::new(vec![Magenta, Blue, Green, Yellow, Red])
|
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 {
|
pub fn sample(&self, fill: f32) -> Color {
|
||||||
let pos = self.values.len() as f32 * fill;
|
let pos = self.values.len() as f32 * fill;
|
||||||
let index = pos as usize;
|
let index = pos as usize;
|
||||||
@ -65,6 +69,12 @@ pub enum PalletEnum {
|
|||||||
Rainbow
|
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<PalletEnum>, rng: &mut impl Rng) -> PalletEnum {
|
pub fn choose_pallet(mut options: Vec<PalletEnum>, rng: &mut impl Rng) -> PalletEnum {
|
||||||
if options.is_empty() {
|
if options.is_empty() {
|
||||||
options.push(PalletEnum::Red);
|
options.push(PalletEnum::Red);
|
||||||
@ -79,6 +89,9 @@ pub fn choose_pallet(mut options: Vec<PalletEnum>, rng: &mut impl Rng) -> Pallet
|
|||||||
options.into_iter().choose(rng).unwrap()
|
options.into_iter().choose(rng).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates the requested pallet.
|
||||||
|
/// # Arguments
|
||||||
|
/// * `pallet`: The pallet type.
|
||||||
pub fn create_pallet(pallet: PalletEnum) -> Pallet {
|
pub fn create_pallet(pallet: PalletEnum) -> Pallet {
|
||||||
match pallet {
|
match pallet {
|
||||||
PalletEnum::Red => Pallet::red(),
|
PalletEnum::Red => Pallet::red(),
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
/// A vector with a x and y axis.
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct Vector {
|
pub struct Vector {
|
||||||
pub x: f32,
|
pub x: f32,
|
||||||
@ -9,6 +10,10 @@ impl Vector {
|
|||||||
Self { x, y }
|
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 {
|
pub fn from_terminal(x: usize, y: usize) -> Self {
|
||||||
Vector::new(x as f32, y as f32 * 2.0)
|
Vector::new(x as f32, y as f32 * 2.0)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user