Chapter 03 · 5 min read
Rain grows, sun ripens
Six conditions, a stream that widens, ice, snowmen and storms that fell trees – the rules of nature.
Nature takes its turn before the gardener does. The weather engine is a small, pure function: it takes yesterday's weather and the garden, and returns the next garden plus a few sentences about what happened. It is deterministic – replaying the log always produces exactly the garden in world.json, and npm run world:check proves it on every pull request.
Six conditions, checked in order
Open-Meteo reports daily values: rain, snow, sunshine hours, the night minimum, gusts. The engine reduces them to one condition – the first rule that matches wins:
| Condition | What it does |
|---|---|
| Storm | Gusts of 62 km/h or more blow away blossoms and fruit. A grown tree may fall (at most one every 60 days) – otherwise a paper boat strands on the sand bank. |
| Snow | From 0.5 cm of fresh snow the garden turns white. Snowmen become possible; they melt with the snow. |
| Frost | A night below 0 °C stops all growth, freezes the stream and makes the annual flowers wilt. Nothing can be planted in frozen ground. |
| Rain | From 1 mm every plant in its growing season grows one stage – two from 10 mm – and the stream rises. |
| Sun | 6 hours of sunshine on a dry day open blossoms and ripen fruit. The stream sinks and the sand bank grows. |
| Grey | A grey day without enough rain or sun: nothing grows, nothing breaks. A good day to water. |
In the year before the garden was planted, Heilbronn had 162 sunny days, 89 rain days, 53 nights of frost, 16 snow days and 12 storms. That mix is what the simulated year on the home page grew under.
The stream widens, the sand banks grow
The stream runs through a trough near the east end of the garden. Its level goes from 0 (a dry bed) to 8 (brimming): rain raises it, sun lowers it. Because the trough is curved, a higher level is also a wider stream – and when the water sinks, sand banks appear on both sides. Frost freezes it; the ice melts on the first day above 5 °C.
Storms and the paper boat
A storm blows away every blossom and every apple. If a tree is grown enough (45 % of its full size), the tallest one falls – at most one every 60 days. The fallen log stays in the garden: mushrooms can grow near it, and the gardener can build a bridge from it. No tree to fell? Then the storm strands a paper boat on the sand bank, and the next heavy rain carries it away.
The plants and their rules
Every plant has planting months, a growing season, a place it likes and neighbours it needs – or avoids. Lavender needs full sun, ferns need shade, mushrooms need wood. All of it is enforced in code, and RULES.md is generated from the same tables:
| Plant | Rules |
|---|---|
| oak | planted Mar–Apr, Oct–Nov on the meadow or the stream bank; grows on rain in Mar–Oct; fully grown at stage 110; 6 columns from other trees and 4 from the garden's edge. |
| birch | planted Mar–Apr, Oct–Nov on the meadow or the stream bank; grows on rain in Mar–Oct; fully grown at stage 90; 5 columns from other trees and 4 from the garden's edge. |
| pine | planted Mar–Apr, Sep–Nov on the meadow; grows on rain all year; fully grown at stage 100; 5 columns from other trees and 4 from the garden's edge. |
| apple tree | planted Mar–Apr, Oct–Nov on the meadow; grows on rain in Mar–Oct; fully grown at stage 80; 6 columns from other trees and 4 from the garden's edge; blooms in the sun Apr–May from stage 24; apples ripen in the sun Aug–Oct. |
| willow | planted Mar–May, Oct–Nov on the stream bank; grows on rain in Mar–Oct; fully grown at stage 90; 6 columns from other trees and 4 from the garden's edge. |
| lavender | planted Apr–Jun, Sep on the meadow; grows on rain in Apr–Sep; fully grown at stage 12; 2 columns from other shrubs; needs full sun – no grown tree within three columns; blooms in the sun Jun–Aug from stage 5. |
| fern | planted Mar–May, Sep–Oct on the meadow or the stream bank; grows on rain in Apr–Sep; fully grown at stage 10; 2 columns from other shrubs; needs shade – a tree of stage 16 or more within four columns. |
| reed | planted Mar–Sep on the sand bank or the stream bank; grows on rain in Apr–Sep; fully grown at stage 12; blooms in the sun Jul–Oct from stage 6. |
| sunflower | planted Apr–Jul on the meadow or the stream bank; grows on rain in Apr–Oct; fully grown at stage 14; needs full sun – no grown tree within three columns; blooms in the sun Jul–Sep from stage 9; seed heads ripen in the sun Sep–Oct; wilts at the first frost. |
| poppy | planted Mar–May, Sep–Oct on the meadow or the stream bank; grows on rain in Mar–Oct; fully grown at stage 7; blooms in the sun May–Jul from stage 4; wilts at the first frost. |
| tulip | planted Sep–Nov on the meadow or the stream bank; grows on rain in Feb–May; fully grown at stage 7; blooms in the sun Apr–May from stage 5. |
| water lily | planted Apr–Aug on the stream (at least half a unit deep); grows on rain in May–Sep; fully grown at stage 8; blooms in the sun Jun–Aug from stage 4; at most 4. |
| mushroom | planted Sep–Nov on the meadow or the stream bank; grows on rain in Sep–Nov; fully grown at stage 4; needs wood – a fallen log or a tree of stage 24 or more within three columns; at most 6. |