mod.rs
2.9 kB · rust · 98 lines
1/// The run of a seed until it fixes, loops or times out.2pub mod animate;3/// The centred cropping and tiling of a run's frames.4pub mod crop;5/// The elementary automata: their stepping, their space-time diagrams and the card of one rule.6pub mod elementary;7/// The cumulative-visit heatmap frames of a run.8pub mod heatmap;9/// The design masks a rule reads and the lattice they generate.10pub mod mask;11/// The entropy, churn and chaos readings of a run.12pub mod metrics;13/// The run config and the recorded life.14pub mod models;15/// The PNG frames and the gif movie of grids and runs.16pub mod render;17/// The named sources of neighbor-count values, and the counts they lay down.18pub mod sequence;19/// The one-generation advance of a grid.20pub mod step;21/// The chaptered chain of runs, each seeding the next.22pub mod story;2324use crate::two::Cell2d;25use mrlycore::errors::{value_error, Result};2627/// Builds the 3 by 3 Moore mask, every site on but the center.28pub fn moore() -> Cell2d {29 Cell2d::new(mrlycore::cell::moore(2))30}3132/// The edge policy of a life grid.33#[derive(Clone, Copy, Debug, PartialEq, Eq)]34pub enum Boundary {35 /// The fixed dead border.36 Constant,37 /// The toroidal edge.38 Wrap,39}4041impl Boundary {42 /// Returns whether the edges wrap.43 pub fn wrap(self) -> bool {44 matches!(self, Boundary::Wrap)45 }46}4748/// The ending of a life run.49#[derive(Clone, Copy, Debug, PartialEq, Eq)]50pub enum Fate {51 /// The empty fixed point.52 Dead,53 /// The living fixed point.54 Alive,55 /// The periodic cycle.56 Loop,57 /// The generation cap reached before settling.58 Timeout,59}6061impl Fate {62 /// Returns the fate's lowercase name.63 pub fn name(self) -> &'static str {64 match self {65 Fate::Dead => "dead",66 Fate::Alive => "alive",67 Fate::Loop => "loop",68 Fate::Timeout => "timeout",69 }70 }71 /// Parses a fate name, or an error for an unknown one.72 pub fn parse(name: &str) -> Result<Fate> {73 match name {74 "dead" => Ok(Fate::Dead),75 "alive" => Ok(Fate::Alive),76 "loop" => Ok(Fate::Loop),77 "timeout" => Ok(Fate::Timeout),78 other => value_error(format!("unknown fate {other:?}.")),79 }80 }81}8283pub use animate::animate;84pub use crop::{crop, tessellate};85pub use elementary::{86 affine, corner_bits, cube_orbit, gasket, genus, history, lambda, npn_class, outer_totalistic,87 popcount, reversible, rule_degree, rule_name, single_seed, step, surjective, wolfram_class,88};89pub use heatmap::{heatmap, heatmap_range};90pub use mask::{design_mask, lattice_index, mask_offsets};91pub use metrics::{churn, entropy};92pub use models::{Config, Life};93pub use render::{frames, frames_of, frames_with, movie};94pub use sequence::{counts, Counts, Sequence};95pub use step::next_grid;96pub use story::{tell, Chapter, Story};9798pub use mrlycore::ramp::Colorizer;