Interactive demo

Diamond-Square Algorithm

The diamond-square algorithm builds a fractal landscape without any noise function: it starts with four corners and keeps filling in midpoints, each the average of its neighbors plus a random offset that shrinks with every level.

Your browser does not support the HTML5 canvas tag.

Press Play to build the map again from its four corners, or drag the Step slider. Coral points come from a diamond step, amber points from a square step; the lines lead to the points they average.

Controls

Square step of level 7 · grid spacing 1

Display

Legend

  • Points set in earlier steps
  • Diamond step: center of a square
  • Square step: center of a diamond (edge midpoint)

Noise types compared

NoiseOutputBuilt fromWork per sampleSmooth
Value NoiseScalar fieldRandom values on a grid4 grid pointsYes
Perlin NoiseScalar fieldRandom gradients on a grid4 grid pointsYes
Simplex NoiseScalar fieldGradients on a triangle grid3 cornersYes
Worley NoiseScalar fieldRandom feature points9 to 25 cellsNo
Blue NoisePoint setRandom candidates around existing pointsUp to 30 tries per point–
Fractal NoiseScalar fieldOctaves of a base noise1 base noise per octaveYes
Diamond-Square this pageHeightmapDisplaced midpoints of a grid4 neighbors per pointNo
Colors of NoiseSignal or imageWhite noise filtered by frequency1 FFT for all samples–
Domain WarpingScalar fieldFractal noise at warped positionsUp to 5 fractal noisesYes
Curl NoiseVector fieldDerivatives of a noise field4 noise samplesYes
Noise Terrain GeneratorHeightmapStacked noise layersLayers × octaves–

1. Diamond step

The center of every square gets the average of its four corners plus a random offset. Together with the corners, the new centers form a pattern of diamonds, squares turned by 45°.

2. Square step

The center of every diamond, the midpoint of an edge, gets the average of the diamond's four corners, again plus an offset. At the border only three exist. Afterwards the points form squares again, with twice as many per side.

3. Roughness

After every level, the offsets are multiplied by the roughness. With 0.5 the detail shrinks as fast as the grid, like fractal noise with a gain of 0.5; higher values give jagged mountains. Straight creases along the first grid lines are a known artifact of the algorithm.

Credits