Hazel reports · ^report(64) · Gnome world · 2026-11-24 · work in progress · after ^report(63)
Gnome World: Which Parts Are Hazel
Matthew asked, on 2026-11-24: “what parts of gnome world logic are expressed in JS vs Hazel? event handling? physics? global game world state? procedural rendering of trees, and other elements?” This report answers for Gnome world 0.0.103 (matthewhammer/hazeljs-examples 02b73ab), its rules compiled in the page by hazel-jit from the hazeljs branch’s build (#2857).
Outline#
- The split: Hazel decides what the world is and how the gnome moves; JavaScript keeps the state, takes the input, moves everything else and draws.
- One step of the world: Hazel is called once for the gnome and, every sixth step, once a beaver; its share of the step’s time is under 1%.
- Event handling: every input is JavaScript’s; Hazel sees one record a step and answers with one.
- Physics: the gnome’s movement is Hazel; the water, the boulders, the animals and the rabbit’s rules around it are JavaScript.
- The world’s state: all of it in JavaScript; Hazel keeps nothing between calls.
- Procedural drawing: Hazel plans where things are and grows the roots; JavaScript draws everything.
- Why the line falls there: what Hazel in a page can and cannot do well today.
- What next, and how this was put together.
The split#
Hazel decides what the world is and how the gnome moves; JavaScript does everything that touches the tiles, the screen or the clock. By size, the Hazel is 40,213 characters of code in 32 functions (World.hz, comments left out), and the JavaScript 443,696 in 160 functions (app.js): 92% of the code, 70% of it drawing.
The Hazel is a set of pure functions the page calls. Each takes small records and returns one:
| Hazel function | what it decides | when the page calls it | ms a call |
|---|---|---|---|
World.plan | the world from its seed: the land, the layers of rock, the water table, the rivers, the beavers' lodges and dams, the villages, the great trees, the trees, bushes, flowers and mushrooms, and the places under the ground (500 places) | once a world, and at Restart and Load | 2.06 |
World.step (with finish, slope_at, slide_vx, dig_ahead, tile) | the gnome's step: running, jumping, falling, climbing, swimming, the slopes, digging | every step: 60 a second | 0.016 |
World.beaver | a beaver's next job: rest, go to a tree, gnaw it, cut a log, drag it to the dam, lay it | every sixth step, for each of five beavers: 50 a second | 0.0017 |
World.water_row | how high a dam holds its river, by its logs | when a dam's logs change | 0.0004 |
World.greet | a villager's words: 768 greetings, from 166 lines, none said by two villagers | when the gnome stops by a villager | 0.0068 |
World.roots, World.threads | a tree's roots and its mycelium, as lines | the first time a tree is in view | 1.26 |
World.ground, World.dig_steps | each kind of ground: its pores, how water flows through it, its color, the steps to dig it with each digger | once a world (90 digging steps kept) | — |
World.village, World.furnish, World.limbs, World.styles | a village's rooms and their things; a great tree's limbs and what is on each; the sixteen styles of tree house | once a world | — |
The times are each function compiled by hazel-jit, called in the page 2,000 times (the plan 5, the roots 20) and averaged, once, on the laptop.
One step of the world#
In a step (a sixtieth of a second), the page calls Hazel once, for the gnome, and every sixth step once for each of the five beavers; everything else in the step is JavaScript. World.step takes 0.016 ms of a step of about 2.4 ms before drawing; the water alone takes 2.2 ms. Then the frame is drawn, all of it in JavaScript.
tick runs it (the yellow bar sweeps across it), then the drawing; Hazel’s parts on the top lane. Below, the step to scale: the water, the rest of the JavaScript, and World.step, a line too thin to see. The step’s times were measured during 0.0.102’s development, after its fixes, with temporary timing; the Hazel call’s, at 0.0.103.Event handling#
Every input is JavaScript’s; Hazel sees one record a step and answers with one. Listeners for keys and for the pad’s buttons set S.keys. Each step the page packs the held keys into a Pad record (dx, up, down, jump, dig) and calls World.step(gnome, near, pad). The step answers with the gnome as it is now, its ev saying what happened, and the page makes the effects: the dug tile taken out of the arrays (digOut), a sound, a heart lost.
Building (B), riding (R), the map, saving, loading and restarting never pass through Hazel. Nor does the speed run’s planning: it finds its way over the tiles in JavaScript and then presses the keys, so the gnome it drives still moves by World.step.
Physics#
The gnome’s movement is Hazel; every other thing that moves is JavaScript. World.step moves a box 0.66 tiles wide and 0.88 tall in thousandths of a tile: running at 92 a step, eased; falling 11 faster a step, to 267 at most; a jump of −208 cut short when up is let go; climbing at 70; floating, swimming and diving; walking on the diagonals of sloped banks and sliding down them; digging the tile pushed into. It sees the world only as the 3 by 5 tiles round the gnome, packed into five whole numbers.
JavaScript moves the rest, each step: the water seeping through the ground (every wet tile, down and then across), the boulders falling, the pebbles, the wind and its gusts, the leaves, the birds’ flights, the squirrels along the branches, the frogs’ jumps, the bunnies’ hops, the villagers walking and a felled tree falling. The beavers are both: World.beaver decides each one’s job, and JavaScript eases its body toward where Hazel put it.
Clover the rabbit is Hazel’s gnome step with JavaScript rules around it. The page changes what the step sees (the window above), what it is asked (twice as fast: dx 2) and what comes back: a hop’s or a leap’s speed set after the jump, the digging’s progress tripled, a landing in the water undone. It went in JavaScript because World.hz is full: one more top-level definition overflowed the browser’s stack building the module on 2026-11-23.
The world’s state#
All of it lives in JavaScript; Hazel keeps nothing between calls. One object, S, holds the gnome, the rivers and dams, the trees, the beavers, the villagers, the animals, Clover, the weather, the camera and the speed run; nine arrays hold the 186,368 tiles (896 by 208): what is there, its water, what is behind and on it, gems, stones, slopes and roots, and the top of each column, about 2.05 MB.
So saving is JavaScript’s: a save file is the seed and a snapshot of S and the tiles, and the GitHub check hashes its 36 parts before a save and after a load. The plan is never saved: Hazel makes it again from the seed.
Procedural drawing#
Hazel plans where things are and grows the roots; JavaScript draws everything, 311,422 characters of canvas code.
- Trees. World.plan puts each tree down with its kind and height. JavaScript grows its limbs (
growLimbs: forking from seeded random numbers), puts leaf pads from eight shapes at their tips, and paints the tree once into a picture, in strips eight tiles tall for the biggest. - Great trees. Hazel gives each limb (
World.limbs: how high, which side, how long, the house on it); JavaScript grows the drawn crown to reach them. - Roots and mycelium. Here Hazel draws too:
World.rootsandWorld.threadsgrow each tree’s roots and threads as lines, as Gnome dig grows them, and JavaScript strokes the lines. - Everything else, the gnomes, birds, rabbits, houses, rivers and sky, is JavaScript.
Why the line falls there#
Hazel takes what is a function of small records; JavaScript keeps what is big, changing or drawn. What Hazel in a page cannot do well today decides most of the rest:
- No arrays: 186,368 tiles a step is a loop over typed arrays in JavaScript.
- One module’s size: World.hz is at the browser’s limit for building one module (32 top-level definitions), and a module that calls another costs the build seconds.
- The page’s edge: whole numbers past 2³¹ from JavaScript arrive cut to 32 bits; tuples do not cross, records do; every crossing converts values.
- Speed: compiled by hazel-jit, a step is 0.016 ms; interpreted (hazeljs 0.0.4 from npm), the page’s own note says about 4 ms, too slow for 60 steps a second with drawing.
What next#
- Clover’s ride in Hazel. A Ride module of its own, calling nothing in World: the hop, the leap, and what she may climb or swim, from the same window of tiles.
- The animals’ minds in Hazel, as the beavers’. A bird’s or a bunny’s next move from a small record: where it is, how far the gnome is, the perches near.
- The water in Hazel, once Hazel has arrays. With ^ticket(846)’s sequences, a row at a time, timed against the JavaScript’s 2.2 ms.
- Tree shapes as Hazel geometry, like the roots. World.limbs already plans a great tree’s limbs; the drawn limbs could come back from Hazel as lines.
- Time the crossing. Gnome, Near and Pad go in and a Gnome comes out 60 times a second; with the converters by declared type (#2857), measure what that costs.
How this was put together#
Read World.hz, preamble.hz and app.js at matthewhammer/hazeljs-examples 02b73ab (0.0.103). Sizes: each Hazel top-level definition’s code with its comments taken out; the JavaScript’s top-level functions grouped by name (drawing: draw*, paint*, sprites, the gnome, birds, rabbits, trees, the HUD; simulation: tick and the steps it calls, the ride; building the world: build and its helpers; the speed run: bot*; save and load; the rest). Times: in the page with ?test=1, on the laptop, in the app’s browser pane (Chromium), the rules compiled by hazel-jit from build.hazel.org’s hazeljs build; each Hazel function called the stated number of times and averaged, once (one run is not a trend). The step’s 2.4 ms and the water’s 2.2 ms come from timing added for a while during 0.0.102’s development. The roots are World.roots’ and World.threads’ own output for the first oak of world 7.
The data#
- The numbers, for programs too: every table in this report, and what its numbers measure, is also in this page as JSON, in its
<script type="application/json" id="report-data">element, so a reader or an agent that fetches the page alone has the dataset. The same, with any raw files that survive, is in064/data/.