Core concepts

A Stigmery model has four moving parts.

World

A grid of square cells called patches. You choose the width, height, and how big each patch renders. Edges can either wrap (a torus) or act as hard walls.

Patches

The cells underneath everything. They can hold properties - for example grass (a number) or burning (a boolean) - and can run their own rules each tick. Most simple models barely touch patches; ecological and spatial models lean on them heavily.

Agents

The mobile entities walking around on top of the patches. Every agent belongs to an agent type (e.g. sheep, wolf, boid) and carries:

whatever you need.

Appearance

Every agent type has an appearance:

shape:  'circle' | 'triangle' | 'square' | 'arrow'
color:  a CSS color or an expression that returns one
size:   a number or an expression

color and size are evaluated per agent, per frame, so you can make appearance react to state. Wolves-and-Sheep uses literal strings (in quotes) so the DSL doesn't treat them as identifiers:

color: "'red'"
color: "energy > 5 ? 'green' : 'pink'"
size:  "1 + energy / 50"

Patches have an appearance.color expression too - the wolves-and- sheep model paints empty patches brown and grass-covered patches green with a single rule:

color: "grass > 0 ? 'green' : 'brown'"

Rules

The verbs of the model. A rule has a name, a when condition, and a do action. Rules live in one of four scopes:

you create initial agents.

for global bookkeeping.

This is where most behaviour lives.

Each tick is just: evaluate go_rules, then every patches.rules for every patch, then every agent_type.rules for every agent. Order within a scope is the order you wrote them in.

Try it in the app

Everything described here works in the live editor. Open Stigmery and follow along.

Open the app →