#![doc = include_str!("../README.md")] #![deny(missing_docs)] use mrlycore::colors::{Color, Theme, DARK, LIGHT}; use mrlycore::MrlyError; use std::cell::Cell; use wasm_bindgen::prelude::*; /// The Apollonian gasket: a packing grown from its root quadruple in exact integers, the Ford circles it rests on the line, and the Farey stack they shadow. pub mod apollonian; /// The elementary automata: their rows stepped, their space-time diagrams and the card of one rule. pub mod automata; /// The universes: codes, symmetries, counts, closed-form fills and names. pub mod bang; /// The blends: registry sequences drawn as terms, ratios, differences and the recurrence they satisfy, and the term operations that mix two of them. pub mod blend; /// The slice carry automaton: its digit polynomial, its even block, its ladder, its sign law and its spectral ratio. pub mod carry; /// The census: which integers the whole registry writes inside a pinned window, how often, and which rows write one. pub mod census; /// The Chladni stills: soups stepped on big design masks by FFT convolution, the kernel drawn, the spectrum and its ring profile read. pub mod chladni; /// The exact crops: the designs trimmed to rational shapes, tallied, swept, drawn and masked. pub mod crop; /// The design Mobius meter: its elements, the meter drawn against log x, its density echo and residual, and the ordinates its spectrum carries. pub mod echo; /// The alphabet: text laid out as a grid, written in stroke order, cycled, and read glyph by glyph. pub mod font; /// The elementary formulas: eight partial sums, products and prime counts read at one depth and walked to it. pub mod formulas; /// The primes of the plane: the Gaussian and the Eisenstein windows painted, counted, clicked and weighed by norm. pub mod gauss; /// The networks of the designs: nodes, branches, roles and censuses, and the force layout that relaxes them. pub mod graph; /// The laboratory: the sequence press and the moire presets. pub mod lab; /// The lattice: the Farey nodes, the totients and the window the stack lights, counted, painted and walked into pi. pub mod lattice; /// The ledger: every measure of every design as a sequence, searched, identified and read against the curated records. pub mod ledger; /// The life grids stepped, run and driven by sequences. pub mod life; /// The magic words: the folded design, its census, its press readings and its prefix rates. pub mod magic; /// The memory designs: a rule on `k` consecutive digits read, the words it accepts drawn, and the Perron root that measures them. pub mod memory; /// The standing patterns of a design mask: its eigenvalue field on the frequency torus, one eigenvalue, the large-values count and a real mode. pub mod modes; /// The Thue-Morse word: its two constructions, its plane lifts, its runs and the difference filter. pub mod morse; /// The primes: the sieve stepped, the stone pile, the count chart and the carpet witness. pub mod prime; /// The race: seeded walkers loose on a flat design. pub mod race; /// The radix designs: a base in a ring of the plane, a digit per residue class with a unit twist, the points they place and the glue they collide into. pub mod radix; /// The crossing shell of a circle on a design, read as a rooted tree and painted. pub mod shell; /// The punctured schedules: the Wallis sieve rastered, its punctures listed, its ratios walked and its limits read. pub mod sieve; /// The hexagon projections of a cube as SVG. pub mod six; /// The snail: the whole numbers wound on the square spiral with every grown cell a design tile whose side is a power of the base. pub mod snail; /// The Laplacian spectra of the designs: eigenvalues, degeneracy and the spectral exponent. pub mod spectrum; /// The turntable: designs, moire fields and slices spun about their centre into ring profiles and wheels. pub mod spin; /// The spirals: the whole numbers wound on a square or hexagonal sheet, painted, clicked and read along a quadratic. pub mod spiral; /// The spirograph: a flat design as the wheel, a pencil in every cell, rolled on a line, a circle or a polygon. pub mod spirograph; /// The ghost star of the hexagon moire: the stacked cut, the band it is measured on, the arm ink law and the cell-frame decay. pub mod star; /// The cubes as packed faces, filled cells and censuses. pub mod three; /// The tessellations: a design repeated across the plane, the cube and the hexagonal mesh, drawn and counted. pub mod tile; /// The tourbillon: the odd parity carpets spun about the centre, one angle per layer, stacked inside the inscribed disc. pub mod tourbillon; /// The inner tube of a design: its distance field, the tube area at a radius, the Minkowski profile and the closed limit of the interior-hole class. pub mod tube; /// The flat designs as byte grids, painted pixels and censuses. pub mod two; /// The cube designs stacked into a moire volume: its faces at a level, and the planes that cut it. pub mod volume; /// The mass side of a weighted design: its level-L mass field, the pressure, the multifractal spectrum and the local dimensions. pub mod weights; /// The critical line: zeta walked at one half plus i t, its zeros counted and listed, and the prime staircase against the explicit formula. pub mod zeta; // THEME thread_local! { static DARK_MODE: Cell = const { Cell::new(true) }; } /// Switches every sheet painted from now on to the dark theme, or to the light one. #[wasm_bindgen] pub fn set_theme(dark: bool) { DARK_MODE.with(|mode| mode.set(dark)); } pub(crate) fn theme() -> &'static Theme { if DARK_MODE.with(Cell::get) { &DARK } else { &LIGHT } } pub(crate) fn rgba(c: Color) -> [u8; 4] { [c.r, c.g, c.b, c.a] } // SHEETS /// A byte grid: its width, its height and its row-major types. #[wasm_bindgen(getter_with_clone)] pub struct Grid { /// The count of columns. pub width: u32, /// The count of rows. pub height: u32, /// The type of every site, row by row. pub types: Vec, } /// A pixel sheet: its width, its height and its row-major RGBA bytes. #[wasm_bindgen(getter_with_clone)] pub struct Pixels { /// The count of columns. pub width: u32, /// The count of rows. pub height: u32, /// Four bytes per pixel, row by row. pub rgba: Vec, } /// The one error a call raises: a message the page catches as a thrown Error. #[derive(Debug)] pub struct Fault(String); impl Fault { fn new(message: impl Into) -> Fault { Fault(message.into()) } } impl From for Fault { fn from(error: MrlyError) -> Fault { Fault(error.to_string()) } } impl From for JsValue { fn from(fault: Fault) -> JsValue { JsError::new(&fault.0).into() } } impl Pixels { fn of(width: usize, height: usize, colors: Vec<[u8; 4]>) -> Pixels { Pixels { width: width as u32, height: height as u32, rgba: colors.concat(), } } } fn code_of(text: &str) -> Result { text.trim() .parse() .map_err(|_| Fault::new(format!("code {text:?} is not a whole number."))) } fn checked(code: &str, dimension: usize, base: usize) -> Result { let code = code_of(code)?; mrlymath::bang::code_to_corners(code, dimension, base)?; Ok(code) }