Raindrop

Struct Raindrop 

Source
pub struct Raindrop<'a, T>
where T: ColorAlgorithm,
{ /* private fields */ }
Expand description

A Raindrop describes a single ‘falling stream’ of randomized characters

Raindrops consist of a ‘leader’ and a ‘follower’. The leader is a continuously (per frame) randomized single character at the bottom of the raindrop. The follower is a string of characters that follow the leader. They have randomized length and content, but unlike leaders, are randomized only once (at instantiation) rather than continuously (per frame)

Implementations§

Source§

impl<'a, T> Raindrop<'a, T>
where T: ColorAlgorithm,

Source

pub fn gen_char(&mut self) -> char

Returns a (pseudo)randomly generated character from the internal charset

Source

pub fn new( charset: &'a Vec<char>, color_algorithm: T, advance_chance: f64, terminal_height: u16, ) -> Self

Returns a new Raindrop instance

charset should be a reference to Vector of chars.

color_algorithm should implement ColorAlgorithm. It defines how follower characters will be colored.

advance_chance is the chance that, on any given frame, this Raindrop will advance its animation. This can be any real number within the range [0.0, 1.0). If the advance_chance is 1.0, this Raindrop will always advance its animation.

terminal_height should be the current height of the terminal, in rows.

§Panics

This function panics if advance_chance is outside the range [0.0, 1.0)

§Examples
use mrs_matrix::raindrop::{Raindrop, color_algorithms};
use crossterm::terminal;

let charset = vec!['a','b', 'c'];

let color_algorithm = color_algorithms::LightnessDescending{
    hue: 118.0,
    saturation: 0.82
};

let advance_chance = 0.75;

let term_height = terminal::size().unwrap().1;

let new_raindrop_instance = Raindrop::new(&charset, color_algorithm, advance_chance, term_height);
// do something with instance
Source

pub fn reinit_state(&mut self, terminal_height: u16)

Re-initializes the state of the Raindrop instance

Uses an internally cached random number generator to generate pseudorandom follower chars and sets the row index to a pseudorandom value less than (visually ‘above’) row 0.

terminal_height should be the current height of the terminal, in rows

§Notes

The Raindrop::new function uses this function internally to set the initial state. Calling this function manually is similar to creating a new Raindrop instance outright, but avoids the need to create a new Rng.

Source

pub fn get_char_at_row(&mut self, row_index: u16) -> Option<char>

Returns the character that should be printed for a given row

§Notes

This function returns an Option. When requesting a char for a row that this instance has no char for (for example, because this raindrop is above the provided row), None will be returned. If this instance does have a char for the provided row, Some(char) is returned.

Source

pub fn get_styled_char_at_row( &mut self, row_index: u16, ) -> Option<StyledContent<char>>

Returns the character that should be printed for a given row with appropriate styling

Internally, uses get_styled_char to retrieve the actual character. Then applies a color according to this Raindrop’s color_algorithm

The leader of the raindrop will always be styled white (and bolded).

Source

pub fn move_drop(&mut self)

Moves the Raindrop down one row.

To reset to the top, use reinit_state.

Source

pub fn is_visible(&self, terminal_height: u16) -> bool

Returns true if Raindrop displays any chars on a terminal of height terminal_height; false otherwise

Source

pub fn advance_animation(&mut self, terminal_height: u16)

Advance the Raindrop by one ‘frame’

terminal_height should be the current height of the terminal, in rows.

This is similar to move_drop, with two key differences:

  • If the Raindrop is not visible because it has fallen down below the bottom of the terminal, reinit_state is called to re-randomize the Raindrop and move it slightly above the top of the terminal.

  • If the Raindrop has had its advance_chance set to some value that is not 1.0, this function will only have a chance of advancing this raindrop’s position. If you want to move the Raindrop for certain, use the move_drop method

Auto Trait Implementations§

§

impl<'a, T> Freeze for Raindrop<'a, T>
where T: Freeze,

§

impl<'a, T> !RefUnwindSafe for Raindrop<'a, T>

§

impl<'a, T> !Send for Raindrop<'a, T>

§

impl<'a, T> !Sync for Raindrop<'a, T>

§

impl<'a, T> Unpin for Raindrop<'a, T>
where T: Unpin,

§

impl<'a, T> !UnwindSafe for Raindrop<'a, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V