Skip to content
Math Background Studioby GordonKit
Open Studio

Contour

Topographic contour lines traced over layered simplex noise.

Open Contour in Studio

Contour background example

Contour draws the lines of a topographic map: every line joins points of equal height on an imaginary landscape. The landscape is invented from noise, so no two seeds give the same terrain.

How the maths works

c₁c₂c₃h(p)
A cross-section of a landscape cut at a few fixed heights (dashed). Joining the crossings at each height gives, seen from above, the rings of a contour map.
Formula
Height: fractional Brownian motion (o = octave)
h(p) = Σₒ 0.5ᵒ · noise(2ᵒ · f · p)
Contours: height split into L levels
h(p) = c₁, c₂, …, c_L

The height h is fractal Brownian motion: simplex noise at frequency f, plus a copy at twice the frequency and half the height, and so on for each octave. The big waves shape hills and valleys, the small ones add rocky detail — the same trick used to generate terrain in games.

The range of heights on screen is split into L equal steps, and marching squares traces where the surface crosses each step: the height is sampled on a grid, and every grid cell whose corners lie on both sides of a level gets a short segment. Joined together, the segments form closed contour lines.

Warp first nudges each point by another noise field before measuring the height, which bends ridges into swirls. You can also replace the noise with your own formula f(x, y) — try sin(x) * cos(y) for an egg-crate grid or r for concentric rings.

Parameters

Levels
How many contour lines, or colour bands, divide the height range.
3 to 40
Frequency
How many noise cycles fit across the short side. Higher values give smaller hills.
0.2 to 6
Octaves
How many layers of finer noise are added. 1 gives smooth blobs; more octaves give rugged coastlines.
1 to 6
Smoothing
Blurs the height field before tracing, rounding off small wiggles in the lines.
Ratio, 0 to 1
Warp
How strongly the landscape is twisted by a second noise field. 0 turns it off.
Ratio, 0 to 1
Fill
Bands fills each step between levels with a colour; Lines draws only the contour lines.
Bands · Lines
Line width
Line width, relative to the short side of the canvas.
0.0005 to 0.01
Height f(x, y)
Leave empty to use noise, or enter a height formula of x, y, r and theta to draw its contour lines instead.
Your own formula of x, y, r, theta
Blur
Overall blur, relative to the canvas short side. 0 means no blur; larger values soften the lines into a glow.
0 to 0.04

Examples

Each example opens in the studio with these settings.

Using it as a background

Bands with a gradient palette read like a relief map; Lines with a single colour look like a hiking map and stay quiet behind text.

The terrain is sampled over the whole canvas at the same scale, so a 9:16 canvas simply shows more landscape rather than stretching it.