Skip to main content

An extensible cellular automaton simulator with GUI, export features, and plugin support

Project description

LifeGrid

A feature-rich cellular automata simulator with a modern Tkinter GUI, headless CLI, REST/WebSocket API, GPU acceleration, and plugin support.

Python 3.11+ License MIT Version 3.2.0


Features

Automata Modes

Mode Rule / Description
Conway's Game of Life B3/S23 — the classic
HighLife B36/S23 — supports replicators
Immigration Two-color Conway variant
Rainbow Multi-color Conway variant
Langton's Ant Turing-complete ant on a grid
Wireworld 4-state electronic circuit simulation
Brian's Brain 3-state firing/refractory model
Generations Multi-state fading automaton
Hexagonal Life Hexagonal grid variant
Custom Rules Arbitrary B/S rule strings

GUI

  • Drawing tools — pencil, eraser, stamp, and selection with configurable brush size and shape (square / circle / diamond)
  • Simulation controls — start, stop, step, reset, speed slider, undo/redo (up to 100 states)
  • Pattern library — built-in patterns per mode with a pattern browser and RLE import/export
  • Themes — light and dark themes plus a visual theme editor with custom presets
  • Generation timeline — scrub backward and forward through simulation history
  • Population graph — real-time population-over-time chart in the sidebar
  • Breakpoint system — pause the simulation when population, generation, or density conditions are met
  • Rule explorer — browse 10 named rulesets (Seeds, Day & Night, Diamoeba, etc.) and apply them instantly
  • Command paletteCtrl+Shift+P quick-access to every action
  • Pattern shape search — draw a shape and find matching patterns by similarity
  • Grid overlays — symmetry guides, cell age heatmaps, activity heatmaps
  • Export — PNG snapshots, animated GIF, MP4/WebM video, JSON state, CSV statistics

CLI

Run simulations headlessly for scripting and batch processing:

python src/cli.py --mode conway --steps 500 --export output/result.gif --fps 15

Supports --mode, --rule (custom B/S), --width, --height, --cell-size, --export (png/gif/mp4/webm/csv/json), --fps, --snapshot-every, and --quiet.

REST & WebSocket API

Start the API server:

uvicorn src.api.app:app --reload
Method Endpoint Description
GET /health Health check
POST /session Create a simulation session
POST /session/{id}/step Advance one or more generations
GET /session/{id}/state Get grid state as JSON
POST /session/{id}/pattern Load a pattern by name or RLE
WS /session/{id}/stream Stream simulation frames at ~20 Hz
WS /collab/{id} Multi-user collaborative editing

GPU Acceleration

Optional CUDA-based acceleration via CuPy. Falls back to NumPy automatically when no GPU is available.

pip install cupy-cuda12x   # match your CUDA version

Plugin System

Drop a .py file into the plugins/ directory to add a new automaton mode. See docs/plugin_development.md for details.

Included plugin: Day & Night (B3678/S34678).


Installation

Requirements

  • Python 3.11 or later
  • Tcl/Tk (included with most Python distributions)

Quick Start

git clone https://github.com/James-HoneyBadger/LifeGrid.git
cd LifeGrid
pip install -r requirements.txt
python src/main.py

Development Install

make install-dev

This installs LifeGrid in editable mode with all optional dependencies (docs, export, dev tools).

Build a Standalone Executable

make executable

Uses PyInstaller with the included lifegrid.spec.


Usage

GUI

python src/main.py
# or
make run

Keyboard Shortcuts

Key Action
Space Start / Stop
S Single step
R Reset grid
G Toggle grid lines
C Clear grid
Ctrl+Z Undo
Ctrl+Y Redo
Ctrl+S Export PNG
Ctrl+Shift+P Command palette
D Toggle drawing mode
B Open breakpoint manager
+ / - Zoom in / out
Ctrl+Shift+R Open rule explorer

CLI

# Run Conway for 1000 steps, export animated GIF
python src/cli.py --mode conway --steps 1000 --export sim.gif

# Run HighLife with a 200x200 grid, export MP4 at 30 fps
python src/cli.py --mode highlife -W 200 -H 200 --steps 500 --export video.mp4 --fps 30

# Custom B/S rule, export CSV statistics
python src/cli.py --rule B36/S23 --steps 2000 --export stats.csv

# Run WireWorld for 1000 steps, capturing every 100th frame as an animated GIF
python src/cli.py --mode wireworld --steps 1000 --snapshot-every 100 --export sim.gif

API

# Start the server
uvicorn src.api.app:app --host 0.0.0.0 --port 8000

# Create a session
curl -X POST http://localhost:8000/session \
  -H "Content-Type: application/json" \
  -d '{"width": 64, "height": 64, "mode": "conway"}'

# Step the simulation
curl -X POST http://localhost:8000/session/<id>/step \
  -H "Content-Type: application/json" \
  -d '{"steps": 10}'

Project Structure

LifeGrid/
├── src/
│   ├── main.py              # GUI entry point
│   ├── cli.py               # Headless CLI
│   ├── patterns.py           # Pattern definitions
│   ├── plugin_system.py      # Plugin loader
│   ├── export_manager.py     # PNG/GIF/MP4/WebM/JSON export
│   ├── config_manager.py     # Persistent app settings
│   ├── ui_enhancements.py    # Theme manager
│   ├── automata/             # All automaton implementations
│   ├── core/                 # Simulator, config, undo, boundary modes
│   ├── gui/                  # GUI app, rendering, tools, new features
│   ├── api/                  # FastAPI REST + WebSocket + collaboration
│   ├── advanced/             # Statistics, pattern analysis, RLE, heatmaps
│   └── performance/          # GPU acceleration, benchmarking
├── plugins/                  # User-installable automaton plugins
├── tests/                    # Test suite (71 tests)
├── examples/                 # Example scripts
├── output/                   # Default export directory
└── docs/                     # Documentation

Testing

# Run the full test suite
make test

# Run with coverage report
make coverage

71 tests covering the simulator, all automata modes, boundary conditions, GPU module, CLI, REST API, collaborative sessions, breakpoints, pattern system, statistics, and more.


Documentation

Full documentation is in the docs/ directory:


License

MIT — see LICENSE for details.


Author

Honey Badger Universe

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lifegrid-3.2.0.tar.gz (7.9 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lifegrid-3.2.0-py3-none-any.whl (130.5 kB view details)

Uploaded Python 3

File details

Details for the file lifegrid-3.2.0.tar.gz.

File metadata

  • Download URL: lifegrid-3.2.0.tar.gz
  • Upload date:
  • Size: 7.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for lifegrid-3.2.0.tar.gz
Algorithm Hash digest
SHA256 fb9dc3e701dc079fdce7fd60b40530cf0c6b64cd83884d05c407832e5f502840
MD5 5fe74f97266ee4c300872c5f5028f11a
BLAKE2b-256 d0b5191f48cffcf615ecc7c3950631e4461651e5e6be07edb6b1d624f34d219b

See more details on using hashes here.

File details

Details for the file lifegrid-3.2.0-py3-none-any.whl.

File metadata

  • Download URL: lifegrid-3.2.0-py3-none-any.whl
  • Upload date:
  • Size: 130.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for lifegrid-3.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7312e43ffb042f9feaaeb0a45f9bbda6386cc09f3449af614315b8d2ec2c183c
MD5 87bdc9ed3952557384d4c1fd3f3ea0f1
BLAKE2b-256 0a730a9783e48eff50bf2fc20bc8cac26d0481f920e5c8dc81113298814e3952

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page