pub struct Rain { /* private fields */ }Implementations§
Source§impl Rain
impl Rain
Sourcepub fn new_matrix(elapsed: Duration) -> Rain
pub fn new_matrix(elapsed: Duration) -> Rain
Construct a new rain widget with defaults for matrix rain.
Sourcepub fn new_rain(elapsed: Duration) -> Rain
pub fn new_rain(elapsed: Duration) -> Rain
Construct a new rain widget with defaults for standard rain.
Sourcepub fn new_emoji_soup(elapsed: Duration) -> Rain
pub fn new_emoji_soup(elapsed: Duration) -> Rain
Construct a new rain widget with defaults for emoji soup.
Terminals that render emojis as two characters wide will not enjoy this.
Sourcepub fn with_seed(self, seed: u64) -> Rain
pub fn with_seed(self, seed: u64) -> Rain
Set the random seed for the generation.
The random seed can be configured. Given a constant screen size, results should be reproducible across executions, operating systems, and architectures.
use std::time::Duration;
use tui_rain::Rain;
let elapsed = Duration::from_secs(5);
Rain::new_matrix(elapsed)
.with_seed(1234);Sourcepub fn with_rain_density(self, rain_density: RainDensity) -> Rain
pub fn with_rain_density(self, rain_density: RainDensity) -> Rain
Set the target density for the rain.
This can be configured as an absolute number of drops:
use std::time::Duration;
use tui_rain::{Rain, RainDensity};
Rain::new_matrix(Duration::from_secs(0))
.with_rain_density(RainDensity::Absolute {
num_drops: 100,
});Or a ratio of screen pixels to drops (lower is more dense):
use std::time::Duration;
use tui_rain::{Rain, RainDensity};
Rain::new_matrix(Duration::from_secs(0))
.with_rain_density(RainDensity::Relative {
sparseness: 50,
});The actual number of drops on the screen at any time is randomly distributed between 0 and twice the target.
Preset relative options include:
RainDensity::SparseRainDensity::NormalRainDensity::Dense
Sourcepub fn with_rain_speed(self, rain_speed: RainSpeed) -> Rain
pub fn with_rain_speed(self, rain_speed: RainSpeed) -> Rain
Set the target speed for the rain.
Speed can be configured as an absolute value of pixels per second, or as a preset.
For an absolute speed in pixels per second:
use std::time::Duration;
use tui_rain::{Rain, RainSpeed};
let elapsed = Duration::from_secs(5);
Rain::new_matrix(elapsed)
.with_rain_speed(RainSpeed::Absolute {
speed: 10.0,
});Preset options include:
RainSpeed::SlowRainSpeed::NormalRainSpeed::Fast
Sourcepub fn with_rain_speed_variance(self, rain_speed_variance: f64) -> Rain
pub fn with_rain_speed_variance(self, rain_speed_variance: f64) -> Rain
Set the rain speed variance.
To avoid perfectly consistent patterns, you can configure some variance in the speed of each drop. This can also give an impression of parallax (depth).
For example, a value of 0.1 will cause each drop’s speed to be uniformly
distrbuted within ±10% of the target speed:
use std::time::Duration;
use tui_rain::Rain;
let elapsed = Duration::from_secs(5);
Rain::new_matrix(elapsed)
.with_rain_speed_variance(0.1);The speed of an individual drop will never go below 0.001 pixels / second, but can vary arbitrarily high.
Sourcepub fn with_tail_lifespan(self, tail_lifespan: Duration) -> Rain
pub fn with_tail_lifespan(self, tail_lifespan: Duration) -> Rain
Set the tail lifespan for the rain.
You can make the rain drop tails appear shorter / longer by configuring how long the tail effect lasts:
use std::time::Duration;
use tui_rain::Rain;
let elapsed = Duration::from_secs(5);
Rain::new_matrix(elapsed)
.with_tail_lifespan(Duration::from_secs(5));The drop length is capped at the screen height to avoid strange wraparound effects.
Sourcepub fn with_color(self, color: Color) -> Rain
pub fn with_color(self, color: Color) -> Rain
Set the color for the rain.
You can change the tail color for each drop:
use std::time::Duration;
use tui_rain::Rain;
let elapsed = Duration::from_secs(5);
Rain::new_matrix(elapsed)
.with_color(ratatui::style::Color::LightGreen);The color of the head is independently configured. The bold / dim effects that automatically get applied over a drop’s length may tweak the color inadvertently, but this can be disabled.
Sourcepub fn with_head_color(self, head_color: Color) -> Rain
pub fn with_head_color(self, head_color: Color) -> Rain
Set the head color for the rain.
You can change the head color for each drop:
use std::time::Duration;
use tui_rain::Rain;
let elapsed = Duration::from_secs(5);
Rain::new_matrix(elapsed)
.with_head_color(ratatui::style::Color::Green);The color of the tail is independently configured. The bold / dim effects that automatically get applied over a drop’s length may tweak the color inadvertently, but this can be disabled.
Sourcepub fn with_bold_dim_effect(self, bold_dim_effect: bool) -> Rain
pub fn with_bold_dim_effect(self, bold_dim_effect: bool) -> Rain
Set whether to apply the bold / dim effect.
By default, the lower third of each drop has the bold effect applied, and the upper third has the dim effect applied. This produces an impression of the drop fading instead of abruptly ending.
This may tweak the color of glyphs away from the base color on some terminals, so it can be disabled if desired:
use std::time::Duration;
use tui_rain::Rain;
let elapsed = Duration::from_secs(5);
Rain::new_matrix(elapsed)
.with_bold_dim_effect(false);Sourcepub fn with_noise_interval(self, noise_interval: Duration) -> Rain
pub fn with_noise_interval(self, noise_interval: Duration) -> Rain
Set the interval between random character changes.
A more subtle effect is that glyphs already rendered in a drop occasionally switch characters before dissapearing. The time interval between each character switch is per-glyph, and can be adjusted:
use std::time::Duration;
use tui_rain::Rain;
let elapsed = Duration::from_secs(5);
Rain::new_matrix(elapsed)
.with_noise_interval(Duration::from_secs(10));Sourcepub fn with_character_set(self, character_set: CharacterSet) -> Rain
pub fn with_character_set(self, character_set: CharacterSet) -> Rain
Set the character set for the drops.
The simplest option is to provide an explicit set of characters to choose from:
use std::time::Duration;
use tui_rain::{CharacterSet, Rain};
let elapsed = Duration::from_secs(5);
Rain::new_matrix(elapsed)
.with_character_set(CharacterSet::Explicit {
options: vec!['a', 'b', 'c'],
});More performant is to provide a unicode range:
use std::time::Duration;
use tui_rain::{CharacterSet, Rain};
let elapsed = Duration::from_secs(5);
Rain::new_matrix(elapsed)
.with_character_set(CharacterSet::UnicodeRange {
start: 0x61,
len: 26,
});Preset unicode ranges include:
CharacterSet::HalfKanais the half-width Japanese kana character set (used in the classic matrix rain)CharacterSet::Lowercaseis the lowercase English character set
Trait Implementations§
impl StructuralPartialEq for Rain
Auto Trait Implementations§
impl Freeze for Rain
impl RefUnwindSafe for Rain
impl Send for Rain
impl Sync for Rain
impl Unpin for Rain
impl UnwindSafe for Rain
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more