Core concepts

A Stigmery model has four moving parts.

World

A grid of squares called patches. You choose its width and height, and how big each patch is drawn. Its edges either wrap around (a torus) or act as hard walls.

Patches

The squares underneath everything. They can hold properties, for example grass (a number) or burning (true or false). They can also run their own rules each tick. Most simple models barely use patches. Models of landscapes and spreading lean on them heavily.

Agents

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

  • a position (x, y) on the world,
  • a heading (degrees, 0 = east),
  • a unique id,
  • the properties you give its type, such as energy or age.

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 worked out for each agent, every frame. So an agent's look can follow its state. Wolves and Sheep puts colours in inner quotes, so the DSL reads them as text and not as names:

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 grassy patches green with one line:

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:

  • setup_rules run once when you click Setup. Create your first agents here.
  • go_rules run once per tick, not for any one agent. Use them for model-wide bookkeeping.
  • agent_type.rules run for every agent of that type, every tick. Most of a model's rules live here.
  • patches.rules run for every patch, every tick.

Each tick runs the go_rules first. Then every patch runs the patches.rules, and then every agent runs its type's rules. Within a scope, rules run in the order you wrote them.