For posts tagged maps, the specimen is a topographic map: an imaginary relief, drawn from the seed, of which only the contour lines are kept. The engine builds a relief out of noise, picks evenly spaced elevations, then inks each character according to its distance to the nearest contour line.
A height field
A relief map is a function that assigns an elevation to each point. The contour line at elevation is the set of points where the terrain is exactly :
A map draws these lines for a regular sequence of levels , where is the contour interval. To first order, two neighbouring lines are separated by a horizontal distance
Tight lines signal a steep slope, widely spaced lines flat ground. All the information about the relief goes into the density and shape of the lines.
Noise to make a relief
We need a relief that looks natural without drawing it by hand. The classic answer from computer graphics is procedural noise: a deterministic, continuous function that looks random but can be computed at any point from a seed.
Value noise and gradient noise
Value noise draws a random value at each node of an integer grid and interpolates between the nodes. It is simple, but the maxima and minima fall on the nodes and the grid stays visible.
Gradient noise, introduced by Ken Perlin in 1985 in “An image synthesizer”, draws a random gradient vector at each node. The noise is zero on the nodes; between them, each corner contributes the dot product of its gradient with the vector from the corner to the point, and these contributions are blended by a smoothed interpolation. In one dimension:
where is a blending curve. Perlin first used , then proposed in 2002 , whose second derivative also vanishes at the ends: the relief no longer has breaks in curvature along the grid1. The extrema fall between the nodes, and the noise concentrates its energy around a single frequency, that of the grid.
Octaves and fractal sums
A single noise gives soft hills, all of the same size. A real relief has detail at every scale: massifs, valleys in the massifs, gullies in the valleys. We imitate it by adding up copies of the noise that are finer and finer and weaker and weaker, the octaves:
The lacunarity (often 2) multiplies the frequency from one octave to the next, and the gain (often ) divides the amplitude. The result approximates a fractional Brownian motion in the sense of Mandelbrot and Van Ness: with , a gain corresponds to a Hurst exponent 2. A high gain gives rugged terrain, a low gain smooth terrain dominated by large shapes. Perlin already described the principle in 1985 with his turbulence function, a sum of octaves in absolute value.
Drawing the lines
The classic method: marching squares
We only know on a grid of samples. The marching squares algorithm, the planar analogue of Lorensen and Cline’s marching cubes (1987), draws the lines cell by cell. For a level , each square formed by four neighbouring samples has its corners above or below the level, which gives configurations; a table gives the segment or segments to draw for each, and the crossing point on an edge is placed by linear interpolation between its two ends and :
Two configurations are ambiguous: those where diagonally opposite corners are on the same side (indices 5 and 10). The line can then either separate or join the two high corners; this is usually settled with the mean of the four corners, which estimates the value at the centre.
What the engine does: distance to the level
The specimen does not need segments: it only needs to know which characters a line crosses. So the engine does not use marching squares. It turns the relation from the first section around: to first order, a point where the terrain is lies at a horizontal distance
from the nearest level . Each character is sampled at 2 × 3 points, two across and three down. At each one, the engine computes the height, the gradient by central differences, the nearest level and that distance; the sample is inked if is less than half a line width, 0.3 line heights. The character takes the strongest ink of its six samples, weighted by the share of them that are inked: a character barely grazed stays readable, but lighter than one the line runs straight through. The glyphs do not follow the direction of the line: it is their density, read off the ramp, that draws it. Cells with no line stay empty, like the background of a map.
The first-order approximation breaks down where the gradient vanishes, on summits and passes. The extreme levels, which would only be points, are not drawn: with lines, the contour interval is the range of heights divided by . That range is measured over an area at least 140 columns by 32 rows that contains the grid, so a three-row strip shows the few lines that cross it rather than the whole range squeezed in.
As on topographic maps, one line in five is an index contour: it is drawn thicker (half width of 0.4 rows) with the top of the ramp, the others with its middle. In the browser, the replayed growth draws the levels from the lowest to the highest, like rising water.
This post’s banner label, specimen 0x1641 · isolines · fbm f=0.037 g=0.48 peaks=2 n=7, sums up that genome: base frequency, gain, number of peaks and number of lines.
Reading a contour map
A few rules are enough to read the specimen as a map:
- Lines never cross, since a point has only one elevation. They only touch on a vertical cliff, which smooth noise does not produce.
- Nested closed lines mark a summit or a basin. Without elevation labels, nothing tells one from the other.
- A pass appears between two families of closed lines facing each other, where two summits meet through a saddle. It is the ambiguous case of marching squares seen at a large scale.
- Spacing gives the slope, through the relation . On the specimen, two lines less than 0.6 rows apart merge into a single thick stroke.
- The V shapes of the lines point upstream in a valley and downhill on a ridge.
A specimen’s relief follows no water and no erosion: it is raw fractal terrain, closer to a scale model than to a landscape. Its valleys do not form a hierarchical network as on a real map.
Why the maps tag
Contour lines are the convention that puts three dimensions on a flat sheet. They are also a general mathematical object: the isobars of a weather map, the iso-cost lines of an optimisation problem or the level sets of a loss function all come from the same construction. The maps tag gathers the posts about maps and territories.