singing-cells
v0.1.1
Published
Generate cellular automata and render them to an HTML canvas with WebAssembly
Maintainers
Readme
singing-cells
singing-cells is a Rust and WebAssembly library that generates cellular automata and renders them to an HTML canvas with WebGL2.
Build and publish
wasm-pack build --release --target bundler
wasm-pack pack
wasm-pack publishAPI
Application concerns such as controls, animation scheduling, and page layout belong to the consuming web application.
CellularAutomatonRenderer accepts an HTMLCanvasElement, the number of cell types, the automaton width, and a rule density.
The number of cell types must be between 2 and 16, the width must be greater than 0, and rule density must be between 0 and 1.
Rule and initial-cell generation use the browser's Math.random().
drawFrame() renders the current state and advances the automaton by one generation.
drawAll() generates and renders enough rows to fill the canvas.
The renderer sizes the canvas for its device pixel ratio when constructed.
Create a new renderer after the canvas's displayed size changes.
The package requires a browser with WebAssembly and WebGL2.
Construction and drawing throw JavaScript exceptions when arguments are invalid or required browser and WebGL resources are unavailable.
Call the generated free() method when a renderer is no longer needed.
