Spielwerk 34: Inselkarte

2026-11-19
Spielwerk 34: Inselkarte - Teaser

An island on a sea chart: roll a seed and an island appears with coasts, hills, forests and rivers; four sliders reshape it while they move. The toolbox's new random/noise makes the land: seeded noise as plain functions, recipes as plain data, filled into a Grid2D.

Play it · Source: collection-spielwerk/34-inselkarte · Toolbox 6.2.0 or later

The game

There is nothing to win or lose. "Würfeln" rolls a new island, or you type a seed of your own. The sliders change the current one: how wide the hills are, how many octaves of detail, how much lies under water ("Meer"), how far the coast gets warped ("Verwirbelung"). Height and a second noise for moisture pick the land type of each cell: sea, shallows, beach, meadow, forest, rock or snow. "Grau" shows the raw noise the recipe makes. Click the chart and it tells you what lies there. Leave it alone for ten seconds and it rolls a new island, then another every six.

New in the toolbox: noise

The problem. Generated maps keep coming up: Landshape's lands, the worlds of Urstoff, a map generator. Each game wrote its own noise, with its own constants, and "frequency 0.0083" says nothing about how big a hill will be. A seed shared between two browsers must give the same map, so Math.random is out, and so are Math.sin and Math.pow, whose last bits may differ between engines.

The idea. A noise is a function (x, y) => number in -1..1. A recipe is plain data that says which noise, how wide a hill is in the game's own units and how many layers go on top. make_noise(recipe, seed) turns the data into a function; fill_grid samples it into any Grid2D.

// src/random/noise/ (Noise.ts, NoiseRecipe.ts, NoiseGrid.ts)
simplex_noise_2d(seed): (x, y) => number      // -1..1, one hill or valley per unit
value_noise_2d(seed): (x, y) => number
make_noise(recipe: NoiseRecipe, seed): (x, y) => number
fill_grid(grid, noise, { x0?, y0?, cell_size? }): Grid2D<number>
normalize_grid(grid, range = "unit"): Grid2D<number>   // lowest 0, highest 1

interface NoiseRecipe {
    kind?: "simplex" | "value";
    scale?: number;          // how wide one hill is, in world units
    octaves?: number;        // layers of finer detail
    persistence?: number;    // each octave this share as strong as the one before
    lacunarity?: number;     // each octave's hills this many times narrower
    ridged?: boolean;        // 1 - 2|n|: sharp crests
    warp?: { amount: number; scale: number } | null;   // push samples by a second noise
    offset?: { x: number; y: number };
    falloff?: { x: number; y: number; radius: number } | null;  // sink towards the edge
    range?: "signed" | "unit";
}

scale is the width of a hill one can see, not a frequency. I measured how long a run above zero is along a straight line (0.6955 lattice steps for simplex, 2.125 for value noise), and make_noise divides by it. A test checks that scale: 120 gives hills 120 units wide, give or take 15 %. The game's scale bar shows a hill next to 100 units.

The island is the ready-made islands recipe with the sliders spread over it:

// src/game/Island.ts
export function island_recipe(shape: IslandShape): NoiseRecipe {
    return {
        ...NOISE_RECIPES.islands,
        scale: shape.hill_size,
        octaves: shape.octaves,
        warp: shape.warp > 0 ? { amount: shape.warp, scale: WARP_SCALE } : null,
        falloff: { x: MAP.width / 2, y: MAP.height / 2, radius: ISLAND_RADIUS },
    };
}

fill_grid(this.raw, make_noise(island_recipe(this.shape), this.height_seed), { cell_size: 1.5 });

The chart is 480 by 360 units in 320 by 240 cells. The sea level is a share of the stretched height, so 40 % means the same on every island.

The same everywhere. The permutation is SeededRandom shuffling 0..255. The arithmetic is only + - * /, floor and sqrt, which IEEE 754 makes exact in every browser, and the gradients are written as numbers. A test pins values with toEqual, not toBeCloseTo:

expect(simplex_noise_2d(42)(12.34, -5.67)).toBe(0.1964078517560366);

The warp's seeds are drawn before the octaves', so moving the octave slider adds detail and never moves the swirls.

How long a fill takes. On an i7-11700F, best of several fills:

Recipe 256 × 256, Node 512 × 512, Node 512 × 512, Chromium
hills (4 octaves) 8 ms 30 ms 35 ms
islands (5) 10 ms 43 ms 46 ms
clouds (6) 12 ms 51 ms 57 ms

The plan said a 512 × 512 fill of hills would fit in one frame. It doesn't: a simplex sample costs about 20 ns, as fast as the quick JavaScript libraries get, and 512 × 512 × 4 octaves is a million samples. 256 × 256 fits, and a test holds it under 1/60 s. While a slider moves, the game refills 320 × 240 cells with the warp: 17 ms at 5 octaves, about 31 ms at 7. The sea level only re-sorts the cells.

Rivers turned out to be little code: a drop starts high on the land and steps to the lowest of the eight neighbours it hasn't visited yet. In a hollow it climbs out over the lowest rim, and the cells it went round fill up as a small lake. A river counts once it reaches the sea or another river.

From earlier steps

Embed it

<script src="https://www.game-object.de/tce-elements/tobidot/dll-tce-assets"></script>
<script src="https://www.game-object.de/tce-elements/tobidot/tce-inselkarte"></script>
<tce-inselkarte init-seed="4711"></tce-inselkarte>
Attribute Values Default
init-seed whole number: 1 to 99 999 is the first island, any other seeds the die random
init-intro true / false true

Next

Previous: Spielwerk 33: Feuerwerk · Next: Spielwerk 35: Spielstand · All steps

Comments

captcha