omatrix 0.1.1

A Matrix-style terminal rain animation for Omarchy users
Documentation
use omatrix::{
    charset::Charset,
    sim::{Cell, Simulation, Size},
};

#[test]
fn simulation_is_deterministic_for_the_same_seed() {
    let mut left = Simulation::new(Size::new(12, 8), Charset::default_multilingual(), Some(42));
    let mut right = Simulation::new(Size::new(12, 8), Charset::default_multilingual(), Some(42));

    for _ in 0..24 {
        left.tick();
        right.tick();
    }

    assert_eq!(left.cells(), right.cells());
}

#[test]
fn resize_rebuilds_the_grid_to_the_new_dimensions() {
    let mut simulation =
        Simulation::new(Size::new(10, 6), Charset::default_multilingual(), Some(7));
    simulation.tick();
    simulation.resize(Size::new(5, 3));

    assert_eq!(simulation.size(), Size::new(5, 3));
    assert_eq!(simulation.cells().len(), 15);
    assert!(simulation.cells().iter().all(valid_cell));
}

fn valid_cell(cell: &Cell) -> bool {
    cell.ttl <= cell.max_ttl
}