A forest fire in the city forest, taken apart
How the Eilenriede fire toy works, piece by piece, and where the real science is
The Eilenriede fire is a forest fire toy on the real map of Hannover’s city forest. You light fires, turn the wind, live through a dry summer, cut firebreaks and watch toy fire crews drive out. This article takes it apart: what each piece does, the code that does it, the idea behind it, and what to read to go further.
Built with AI coding tools: I set the direction, tested and decided; the tools wrote the code and the first draft of this article. The reference list was checked against Crossref, and what I say about each source against its abstract or an open copy where one was available. I am not an expert in this field. I am learning it, and this article is my map so far.
A toy, not a model
The map is real. The forest’s outline, its paths, roads, streams and clearings, the city around it, the names on it and the fire stations all come from OpenStreetMap. Everything that happens on the map is made up. No rule was fitted to a measurement, and no number the toy shows says anything about the real forest, its fire risk or the real fire brigade. That is the difference to a model. The last part is about what it would take to cross it.
The toy is still useful to me as a way in. A forest fire on a grid is one of the oldest examples of how simple local rules make large patterns, and the questions it raises (when does a fire get through, how big do fires get) have a mathematics of their own.
The shape of the program
The toy is one HTML file of about 177 KB with no library. Five small Python scripts, standard library only, fetch the map once and turn it into data files; build.py then puts the data, twelve JavaScript modules, a page template and a style sheet into that one file. Drawing is WebGL2 written by hand.
The heart of the frame loop is a clock that turns real time into steps of the fire. At 1× it runs four steps a second; the speed button gives 4× and 10× (from main.js):
const STEPS_PER_S = 4; // at 1×; the speed button gives 4× and 10×
// …
clock += dt * STEPS_PER_S * speed;
let n = 0;
while (clock >= 1 && n < 12) {
// …
rules();
const lit = sky.step();
live.step(rnd);
if (crews) crews.step(rnd);
// …
clock -= 1; n++;
}rules() hands the current dryness and wind to the fire. Then the weather, the fire and the crews each take one step. Drawing happens every frame, whether a step was due or not, so flames flicker and lights move smoothly while the cells change only a few times a second.
From OpenStreetMap to cells
The toy needs a grid: one class per square of ground. fetch_osm.py asks the Overpass API, in one run of a few queries, for the outline of the Eilenriede, the protected-area relation that OpenStreetMap keeps for it, together with its parts (among them the Tiergarten, Hermann-Löns-Park and the Seelhorst), and for every way and area inside: woods, meadows, paths, roads, streams, buildings. rasterise.py turns that into cells of 25 by 25 metres.
The core of it is a scanline fill. For each row of cells it finds where the row’s centre line crosses the polygon’s edges, sorts the crossings, and fills the cells between every other pair (from rasterise.py):
for j in range(H):
yc = j + 0.5
xs = []
for poly in polys:
for (x1, y1), (x2, y2) in zip(poly, poly[1:]):
if (y1 <= yc < y2) or (y2 <= yc < y1):
xs.append(x1 + (yc - y1) * (x2 - x1) / (y2 - y1))
xs.sort()
for a, b in zip(xs[0::2], xs[1::2]):
for i in range(max(0, math.ceil(a - 0.5)), min(W, math.floor(b - 0.5) + 1)):This is the even-odd rule: a point is inside if a line from it crosses the outline an odd number of times, so holes in the forest come out right without extra work. The layers go down in order, later ones winning: the outline as grass, then woods (with OpenStreetMap’s leaf type where it has one), open land, water and built ground, and last the lines: paths, tracks, roads and streams. A line marks every cell whose centre lies within half a cell of it, at least, so that a road always closes the gap between diagonal cells. A thinner line would let fire slip through at the corners.
The grid is stored as one string of letters and run lengths, a letter per class and a number when the class repeats, which keeps the whole grid at about 11 KB. The city around it (buildings, main streets, railways, water, a few landmarks and district names) comes from a third script, the fire stations from a fourth. All of it is OpenStreetMap data, © OpenStreetMap contributors, under the Open Database License; the toy credits it wherever the map shows, and so does every map picture here. A fifth script takes the outline of Germany for the small locator map from Natural Earth, which is in the public domain.
OpenStreetMap itself is a map made by volunteers and free to use; Haklay and Weber (2008) describe the project and how it works.
The cellular automaton
Every cell that can burn is in one of five states: bare, holding a tree (or grass), burning, burnt, or cut by hand. Each step, every burning cell tries once to light each of its eight neighbours. A burning cell stays alight for a few steps (three for wood, one for grass), then is burnt.
A grid of cells, each changing step by step by a fixed rule from the states of its neighbours, is a cellular automaton (Wolfram 1983). The toy’s rule throws dice, which makes it a probabilistic one. Fire is one of the classic uses. Two examples of cellular automata built to predict how a forest fire spreads are Karafyllidis and Thanailakis (1997) and Alexandridis et al. (2008), the second applied to a wildfire on the Greek island of Spetses in 1990.
The whole rule fits in one function that sets a chance for each of the eight directions (from fire.js):
f.setRules = (dryness, wx, wy, strength) => {
const base = 0.04 + 0.5 * dryness;
for (let d = 0; d < 8; d++) {
const [dx, dy] = DIR[d];
const len = Math.hypot(dx, dy);
const along = (dx * wx + dy * wy) / len;
chance[d] = Math.min(1, base * (len > 1 ? 0.7 : 1) * Math.exp(1.7 * strength * along));
}
Object.assign(ember, { p: 0.03 * strength * dryness, x: wx, y: wy, reach: 1 + 6 * strength });
};Dryness raises the chance everywhere. Corners count less than sides. Wind multiplies the chance by a factor that grows with how much a direction points downwind and shrinks upwind. Figure 4 shows the result.
Each step then runs through the burning cells only, never the whole grid (from fire.js):
for (let a = 0; a < n; a++) {
const k = front[a], id = fireOf[k];
if (state[k] !== BURNING) continue; // put out by rain
for (let d = 0; d < 8; d++) {
const j = k + STEP[d];
if (state[j] === UNBURNT && wetTill[j] < tick && rnd() < chance[d] * fuel[j]) { catchFire(j, tick, id); spare[m++] = j; }
}The burning cells live in a list, front. Cells that catch fire, and cells still burning, go into a second list, spare, and at the end of the step the two lists swap. A fire of a hundred cells costs a hundred cells of work, whatever the size of the map.
With wind, a burning cell now and then throws an ember a few cells downwind, with a little random turn. If it lands on a tree, the tree may catch (wood always does); if it lands in the city, it goes out. That is how a fire in the toy can jump a road. It is also why the city never burns: the city has no cells that can.
The summer
The weather is a second, smaller set of rules (from weather.js). Each day, 40 steps long, the forest dries a little more, unless it rains:
if (raining) { w.dry = Math.max(0.05, w.dry - 0.12); w.sinceRain = 0; }
else { w.dry += (1 - w.dry) * 0.035; w.sinceRain++; }Dryness creeps towards 1 but never gets there. Every week or so a cloud drifts over with the wind; tap it and it rains, putting out fires below it with a chance each step. A cloud that thunders may strike a tree when the forest is dry. Burnt, cut and bare cells grow back slowly, burnt ones only after they have cooled. After 100 days the autumn rains come and a new summer starts, with the forest as it is.
When does a fire get through?
Light one cell in a sparse forest and the fire dies after a few cells: too many of its neighbours are empty, and too few of the trees catch. Light it in a dense, dry forest and it runs through. Between the two there is no gentle slope but a fairly sharp change.
This is percolation, studied in mathematics since Broadbent and Hammersley (1957): a medium with random gaps, and the question of whether something can get from one side to the other. In the toy two kinds of randomness meet. Whether a cell holds a tree at all is the kind called site percolation; whether a burning tree lights its neighbour is the kind called bond percolation. Dryness moves the second, the density of trees the first.
Figure 5 is computed with the toy’s own code, on the real map, without wind. For each density of trees and each dryness, 100 fires are lit at random trees, and the chart shows how much of the trees in the fire’s part of the forest one fire burns on average.
At dryness 0.9 the average jumps from about a tenth of the part at 55 % tree cover to about half at 65 %. At dryness 0.6 the rise comes later and is slower. At dryness 0.3 even a full forest stops most fires. The toy starts each forest at 80 % cover, so dryness decides most of what happens.
“Its part of the forest” matters here. Roads and broad gaps split the Eilenriede into 20 parts that touch nowhere, the largest 3,452 cells (about 216 ha). Without embers, a fire can never leave its part. That is a fact about the map, not about fire, but it shapes everything the toy shows.
The storm: 300 strikes
The Storm button asks the toy’s other question: how big do fires get? It copies the forest as it is, lets lightning strike a random tree, burns that fire to the end, and does it again, 300 times, each time on a fresh copy. Every strike becomes a tiny map; when all are done, the maps sort themselves from the smallest fire to the largest, and a chart counts how often each size occurred.
Figure 7 does the same with 3,000 strikes at each of two levels of dryness, 0.42 (where a summer starts) and 0.75 (after a few dry weeks), on one forest with 80 % cover and the toy’s default breeze.
Early in the summer, about a quarter of the strikes in this run stayed under 10 cells and about one in eight reached 1,000 cells or more. Late in the summer, under one in ten stayed that small and about two in three reached 1,000 cells. The single most common size is one cell, and there are fires at every size in between, which is what the logarithmic axes make visible.
Here the toy touches a real debate. Bak, Chen, and Tang (1990) proposed a forest-fire model in the context of self-organised criticality: a system that drives itself, without anyone tuning it, to a state where events of all sizes occur. Drossel and Schwabl (1992) introduced a version with a small chance of lightning and showed that it reaches such a critical state as that chance goes to zero, provided trees grow back much more slowly than forest clusters burn down. Malamud, Morein, and Turcotte (1998) found that the areas of real fires follow power laws over many orders of magnitude, and that a model of this kind behaves similarly.
The toy’s storm is not that model. It strikes a frozen forest, so what it shows is the size of the clusters a fire can reach in one forest at one moment, which is percolation again. The summer, with its regrowth and lightning, is closer in spirit to the self-organised models, but its days are short, its forest small and split into parts, and nothing in it was tested against the theory. The chart’s straight-ish stretch is a hint, not a result.
The fire crews
Seven fire stations from OpenStreetMap (amenity=fire_station) lie inside the map, after the faded rim is left out and two entries about 400 m apart in Misburg are taken as one. Each gets one toy crew. Once a fire has burned for six steps, the nearest free crews leave, more for bigger fires, up to four. You can also tap a station to send its crew. A crew drives to a cell next to the fire, puts out burning cells within six cells of it, wets the trees around it so they do not catch for a while, follows the fire if it gets away, and drives back to fill up when its water runs out.
None of this is how a real fire brigade works, and the toy shows no minutes, distances or arrival times. The speed, reach and water of a crew are made up, in one place (from crews.js):
const CREW = {
speed: 5, // cost units per step (a street cell costs 1)
reach: 6, // cells
douse: 0.6, // chance per step that a burning cell in reach goes out
water: 150, // cells they can put out before driving back
refill: 25, // steps at the station
wet: 80, // steps the trees they spray stay too wet to catch fire
alarm: 6, // steps after a fire starts before crews leave on their own
};Finding the road: a cost field
Each cell has a cost to cross it: 1 for a street, 1.5 for a road, track or path in the forest, 3 for built or sports ground there, 4 for the rest of the forest, 5 for other city ground, 8 for a railway; buildings and water cannot be crossed. A diagonal step costs 1.414 times as much.
From each station the toy computes, once, the cheapest cost to reach every cell of the map. This is Dijkstra’s method (Dijkstra 1959): start with the station at cost 0, always take the cheapest cell not yet finished, and offer each of its neighbours its own cost plus the step. A binary heap (the structure behind heapsort, J. W. J. Williams 1964) hands out the cheapest cell quickly. Here it is written on two plain typed arrays, one for cells and one for costs (from crews.js, shortened):
const push = (k, d) => {
let i = n++;
while (i > 0) { const q = (i - 1) >> 1; if (hd[q] <= d) break; hk[i] = hk[q]; hd[i] = hd[q]; i = q; }
hk[i] = k; hd[i] = d;
};
dist[from] = 0; push(from, 0);
while (n) {
const k = hk[0], d0 = hd[0];
// … take the top off the heap …
if (d0 > dist[k]) continue;
const x = k % W, z = (k - x) / W;
for (let e = 0; e < 8; e++) {
const ii = x + DX[e], jj = z + DZ[e];
if (ii < x0 || jj < z0 || ii > x1 || jj > z1) continue;
const q = jj * W + ii, d = d0 + cost[q] * DM[e];
if (d < dist[q] && n < hk.length) { dist[q] = d; push(q, d); }
}
}The result is a field: one number per cell (Figure 8). The road from the station to any cell is then found backwards. Start at the goal and always step to the neighbour with the lowest number, until the number is 0; that is the station. The toy reverses that list and the crew drives it.
One field serves every fire, which is why the toy computes the whole map once instead of searching for one road at a time. A search for one road would use A*, which steers the search towards the goal with an estimate of the remaining cost (Hart, Nilsson, and Raphael 1968). When a crew must chase a fire that got away, the toy computes a small field around the crew instead, only 70 cells in each direction.
A crew moves along its road with a budget of five cost units per step. Whatever it does not spend is carried over, so it can always pay for a costly cell, such as a railway crossed on the diagonal. A burning cell on the road stops it there.
In one test (six fires, 250 steps each, at dryness 0.6 and wind 0.4, three runs with crews and three without, on a version just before a small fix to how crews are sent) about 28 % fewer cells burned in all with crews, but one run with crews burned more than two without. Large fires in a strong wind still got away. Like every other number here, that describes the toy.
Drawing the night
The view is a tilted map at night, drawn with WebGL2. Three ideas carry it.
The state of the forest is a texture. Each cell of the grid is one pixel of a texture: its kind, its state, how long it has burned or how far it has grown back, and a random number. The ground’s shader reads that pixel for every point on the screen and picks the colour. When cells change, only the forest’s rectangle of the texture is sent to the graphics card again. A second, small texture holds where fire burns, blurred, so that firelight spills orange onto the ground and the trees nearby. The trees are one small cone with five sides, drawn for every cell that can hold a tree (on phones, the small trees along paths are left out) in a single call (instancing), sized and coloured from the same texture.
The city is a filtered texture, not geometry. An earlier version raised the city’s buildings as 3D blocks, and from afar their thin walls and window patterns flickered. Several things were changed against that; the texture is the main one. Now the city is a second texture: buildings, streets and water in its colour channels, with mipmaps, the smaller, pre-filtered copies of a texture described by L. Williams (1983). From afar, the shader reads a small copy in which a street has already been averaged into its surroundings, so nothing flickers. Near, it draws a soft edge about one pixel wide (from shaders.js):
float soft(float v, float px) { float w = clamp(px * 0.3, 0.03, 0.5); return smoothstep(0.5 - w, 0.5 + w, v); }px is how many cells one pixel covers, which the shader gets from the screen-space derivatives of the grid position. Close up the step is sharp; far away it widens into a blend.
Glow is a few passes over the finished frame. The frame is drawn off screen, with four samples per pixel where the device allows (multisampling, against jagged edges), then resolved into a plain texture. A small shader keeps only the bright parts, at a quarter of the size, a blur spreads them, and a last pass adds them back (Figure 9). The bright pass fades in from a threshold, so only fire, lights and lightning glow (from shaders.js):
vec3 pick(vec2 d) {
vec3 c = texture(uSrc, vUv + d * uTexel).rgb;
return c * smoothstep(0.42, 0.95, max(c.r, max(c.g, c.b)));
}The last pass also lifts the colour a little and darkens the corners:
vec3 c = texture(uBase, vUv).rgb + texture(uGlow, vUv).rgb * uGlowK;
float l = dot(c, vec3(0.299, 0.587, 0.114));
c = max(mix(vec3(l), c, 1.2), 0.0); // a little more colour
vec2 q = vUv - 0.5;
q.x *= uAspect;
c *= 1.0 - 0.6 * dot(q, q); // darker towards the cornersThe names on the map, the station labels and the touch rings are drawn on a second, plain 2D canvas on top, so text stays sharp.
Staying fast on a phone
Most of the work is small enough not to matter. Two places needed care.
The roads. In the first version of the crews, a step in which crews left could take long enough to make the picture stutter. After a rewrite (the heap written out on flat typed arrays, every station’s full field computed ahead, one by one, in quiet moments after the page has loaded, and at most one small field per step while fires burn) a full field of the 166,000 cells of the map takes about 16 ms on a desktop computer and a crew’s small field about 2 ms.
The resolution. Phones get a lower pixel density from the start and fewer points for embers, smoke and flames. If frames keep taking longer than about 1/28 of a second, the toy lowers the resolution a little, and again if needed. It stops when the tab is hidden, and visitors who ask their device for less motion get a still picture with a play button.
From toy to model
What would have to change before any of this could say something about a real forest?
Use what is known about fire. Real fire spread is modelled from fuel, moisture, wind and slope. A widely used example is the surface fire spread model of Rothermel (1972), built on laboratory fires, with standard fuel models to go with it (Scott and Burgan 2005). FARSITE (Finney 1998) combines models of this kind to simulate how a fire grows in two dimensions. Sullivan (2009a), Sullivan (2009b) and Sullivan (2009c) survey the field from 1990 to 2007, from physical models to simulation and “mathematical analogue” models, the family the toy belongs to: models based on a mathematical idea rather than the physics of fire.
Use the right data. The toy’s classes come from map tags, not from fuel surveys. Its cell size is fixed at 25 m. It has no terrain and no fuel moisture, only one number for dryness. Its wind is the same everywhere.
Tie the rules to observations, and write them down. A model is only as good as its test against real fires. A standard way to describe such a model so that others can rebuild it is the ODD protocol (Grimm et al. 2006, 2020).
The toy’s rules were not derived from any of these. They are where I would start reading before writing a rule that claims anything.
What the toy leaves out
No terrain, no fuel load, no fuel moisture by place, no crown fire, no smoke that matters. Time has no unit: a step is not a minute and a day is not a day. The crews have nothing to do with how a real fire brigade works, arrives or fights a fire, and the toy says nothing about any real station. The city never burns because the toy gives it no cells that can. All rates and thresholds were set by hand, to play well.
For the real fire danger on a given day, look to the weather services, not to a toy.
A reading guide
Cellular automata and percolation. Percolation (Broadbent and Hammersley 1957) and cellular automata (Wolfram 1983).
Fires as a puzzle of physics. The forest-fire model (Bak, Chen, and Tang 1990), lightning and self-organised criticality (Drossel and Schwabl 1992), and real fires against the model (Malamud, Morein, and Turcotte 1998).
Fire spread on real ground. Cellular automata for real fires (Karafyllidis and Thanailakis 1997; Alexandridis et al. 2008); the surface fire spread model and its fuel models (Rothermel 1972; Scott and Burgan 2005); a fire area simulator (Finney 1998); a survey in three parts (Sullivan 2009a, 2009b, 2009c).
Roads and maps. Shortest paths (Dijkstra 1959), heaps (J. W. J. Williams 1964), A* (Hart, Nilsson, and Raphael 1968), OpenStreetMap (Haklay and Weber 2008).
Drawing. Mipmaps (L. Williams 1983).
Describing a model. The ODD protocol (Grimm et al. 2006, 2020).

