Build living math models in the browser

MathPets is a friendly language and studio for math-powered agent simulations, experiments, and emergent behavior.

fire.petRun
world:  x: -60..60  y: -44..44  topology: box params:  density: number = slider(62, 0..100) monitors:  burned-trees: number = count patches where burned  burning-trees: number = count patches where burning  living-trees: number = count patches where tree patches:  state: empty | tree | burning | burned = empty setup:  patches:    state := if (random-float(100) < density) then tree else empty     where (tree and px = min-x):      state := burning step staged:  patches:    where burning:      state := burned     where (tree and any neighbors4 where burning):      state := burning stop when (count patches where burning = 0) 
step 0burning 0trees 0burned 0

Free self-paced course

Learn agent-based modeling by changing live worlds

Six units of short narrated lessons, runnable experiments, readable source, and end-of-unit checkpoints. No programming background or account required.

  • Emergence, feedback, thresholds, and networks
  • 27 lessons · 6 checkpoints · about 2 hours
Course path self-paced
1
A world of patchesGrids, state, and neighbours
20m
2
Rules that make patternsConway's Life, read straight off the code
16m
3
Pets that moveFlocking: three rules, no leader
20m
4
Food chains and life cyclesWolves, sheep, energy, die and hatch
20m
5
NetworksLinks, contagion, and graph structure
20m
6
Network dynamicsLinks, flow, and collaboration
16m

Write

Describe agents, rules, and data in a small language that reads like the model you are thinking about.

Learn the language

Run

Step through behavior, tune parameters, inspect state, and watch patterns emerge without leaving the page.

Explore simulations

Remix

Fork built-in models, reshape appearances, and save your own browser-local experiments.

See how remixing works

Watch behavior emerge

Every board below is a live simulation — scroll and the rules change under it.

View all models
01

Flocking

Birds align, separate, and cohere using only their nearest neighbors.

No bird is in charge. Watch ribbons and vees assemble out of three local steering rules — then dissolve and reform somewhere else.

Open model
02

Ants

Foragers lay pheromone trails that evaporate, diffuse, and recruit.

The first ant wanders at random. Watch highways condense between nest and food as trails reinforce — and fade once a source is exhausted.

Open model
03

Turing patterns

Two chemicals react and diffuse into spots, stripes, and labyrinths.

Activator and inhibitor race across the grid. The standing pattern that emerges is the same math behind seashell pigment and zebra stripes.

Open model
04

Wolves & sheep

Predators, prey, and grass chase each other through boom and bust.

Populations oscillate without any schedule: too many wolves starve, sheep recover, grass regrows. Sometimes the whole system collapses instead.

Open model

Documentation

Learn the language, explore examples, and master the studio.

Read the docs

Open source

The MathPets language, compiler, and runtime are the open core behind the studio.

Explore the language