Computer Science · Lesson 16

Perlin Noise: Randomness That Looks Natural

Procedural Generation Gradients & Interpolation Octaves & Fractals Game Engines & VFX

Minecraft does not store every hill in its worlds. It stores a single number, the seed, and calculates the land as you walk into it. The tool behind this is Perlin noise, a kind of randomness that changes smoothly the way real terrain, clouds, and wood grain do. In this lesson you will build it one piece at a time, then use it to generate your own worlds.

Live: this coastline is being calculated right now
  1. Why not random?
  2. Build it in 1D
  3. Into 2D
  4. Octaves
  5. World Builder
  6. Beyond terrain
  7. Check yourself
Part 1

Why Plain Randomness Looks Wrong

Ask a computer for random heights with Math.random() and every value is chosen on its own, with no connection to its neighbor. That is white noise. It looks like TV static, and nothing in nature looks like that. A mountain that is 900 m tall at one step is not 12 m tall one step later.

Nature is random but smooth: points that are close together have similar values. The graph below draws the same kind of landscape three ways. Press Roll again a few times and compare them.

  • White noise: a new random number at every step. Jagged and unusable as land.
  • Value noise: random heights only at whole numbers, with the gaps filled in smoothly. Better, but the peaks all land on the grid.
  • Perlin noise: random slopes at whole numbers. Hills and valleys fall between grid points, so the pattern looks less regular.
Discuss: In the value-noise line, where do the highest and lowest points almost always sit? Why would a player notice that pattern after walking across a big map?
Part 2

Build Perlin Noise in One Dimension

Ken Perlin's idea was to place a random gradient (a slope) at every whole number on the line, called the lattice. At a point x between two lattice points, the algorithm does three things:

  1. Follow each neighbor's slope. The left point's slope g₀ gives a height of g₀ · t, where t is how far you are past it (0 to 1). The right point's slope g₁ gives g₁ · (t − 1).
  2. Ease the blend. Pass t through a fade curve so the blend starts and ends gently.
  3. Blend. Mix the two heights using the faded t. This mixing is called interpolation. Near the left point you get mostly the left slope's line, and near the right point mostly the right one's.

Try it: hover or drag across the graph to inspect a point. Drag a purple slope handle up or down to change that gradient. Then switch the fade curve to Linear and look for sharp corners at the grid lines.

Fade curve
x–
t (past left)–
fade(t)–
left: g₀·t–
right: g₁·(t−1)–
noise(x)–
Key idea: At every whole number the noise is exactly 0, because t = 0 there. The slopes decide what happens in between. That is why Perlin noise is called gradient noise: it stores random slopes instead of random heights.

Why the fade curve matters

A linear blend changes direction suddenly at each grid line, and the eye picks up those creases, especially once the noise is lit and shaded. Perlin's 1985 version used smoothstep, 3t² − 2t³. In 2002 he changed it to 6t⁵ − 15t⁴ + 10t³, which also smooths out the curvature, so lighting on noise terrain no longer shows faint grid lines.

Part 3

Into Two Dimensions: A Grid of Arrows

In 2D, each corner of a square grid gets a random arrow, a gradient vector. For any pixel inside a square, the algorithm:

  1. Finds the four corners of the square the pixel is in.
  2. Draws an offset arrow from each corner to the pixel.
  3. Takes the dot product of each corner's gradient with its offset. The result is positive if the gradient points toward the pixel and negative if it points away.
  4. Fades and blends the four numbers: first along x, then along y.

Move over the image (or tap it) to pick a pixel. The four corner values appear next to the corners, green for positive (lighter) and red for negative (darker).

top-left–
top-right–
bottom-left–
bottom-right–
blended–
Look closely: Find a corner whose arrow points right. Is the image lighter or darker just to the right of that corner? Can you predict the brightness near a corner before hovering?
Part 4

Octaves: Mountains, Hills, and Pebbles

A single layer of noise gives gentle rolling hills and no small detail. Real landscapes have big shapes (mountain ranges), medium ones (ridges), and small ones (boulders). So we add several layers, called octaves. Each octave is the same noise, sampled at a higher frequency (zoomed out, so bumps come closer together) and with a smaller amplitude (shorter bumps).

4
0.50
2.0
Why "fractal"? Zoom in on a coastline and you see smaller bays inside bigger bays. Stacking octaves that shrink by the same ratio each time creates that self-similar detail. Summing noise this way is called fractal Brownian motion (fBm).
Predict, then test: What happens to the landscape if persistence is 0.8 instead of 0.5? Make a prediction with a partner, then move the slider.
Part 5

World Builder Lab

This lab puts all the pieces together. Every pixel's color comes from one number, its fBm height, and the style decides how that number becomes a color. Use the Controls panel to change the style, octaves, persistence, and seed. Drag on the map to pan.

StyleTerrain
Seed1983
Octaves5
Water–
Same seed, same world. Type a seed, write down what you see, then press Random seed and type your old seed back in. The world returns exactly as it was. This is how a game can share a whole world with a single short number.
Part 7

The Whole Algorithm in 15 Lines

Here is the 1D version from Part 2 written in JavaScript. The 2D and 3D versions follow the same pattern with more corners.

// one random slope per whole number, fixed by the seed
const slopes = makeSlopes(seed);            // e.g. [0.7, -0.4, 0.9, ...]

function fade(t) { return t*t*t*(t*(t*6 - 15) + 10); }
function lerp(a, b, t) { return a + (b - a) * t; }

function noise(x) {
  const i = Math.floor(x);                 // left lattice point
  const t = x - i;                         // how far past it (0..1)
  const left  = slopes[i]     * t;          // follow left slope
  const right = slopes[i + 1] * (t - 1);    // follow right slope
  return lerp(left, right, fade(t));
}

function fbm(x, octaves) {
  let sum = 0, amp = 1, freq = 1;
  for (let o = 0; o < octaves; o++) {
    sum += amp * noise(x * freq);
    amp *= 0.5;  freq *= 2;               // persistence, lacunarity
  }
  return sum;
}
Trace it: If slopes[3] = 1 and slopes[4] = -1, what is noise(3.5)? (Hint: fade(0.5) = 0.5.) Check your answer in the practice set below.
Part 8

An Oscar for a Math Function

Ken Perlin worked on the computer graphics for Disney's Tron (1982) at a company called MAGI. He disliked how "machine-like" the film's clean, perfect surfaces looked. Real materials have random variation in them. Over the next few years he wrote a noise function that artists could use to add that variation to any surface.

  1. 1982Tron is released. Perlin sets out to make CG surfaces look less perfect.
  2. 1983He develops the first version of his noise function.
  3. 1985He publishes it in "An Image Synthesizer" at SIGGRAPH, the main computer graphics conference.
  4. 1997The Academy of Motion Picture Arts and Sciences gives him a Technical Achievement Award for Perlin noise.
  5. 2001–2002He publishes simplex noise, which is faster in higher dimensions, and "improved noise" with the quintic fade curve you tested in Part 2.

Perlin chose not to patent his original noise, so anyone could use it. That is one reason it spread into every major 3D program and game engine.

Where You Have Already Seen It

🏔️ Infinite worldsMinecraft and No Man's Sky layer noise at different scales to set height, caves, biomes, and where resources appear, all from a seed.
☁️ Clouds, smoke, fogFilm VFX use 3D noise, with time as an extra axis, to drive volumes that swirl and drift instead of repeating.
🪵 MaterialsWood grain, marble veins, rust, and dirt can be generated at any resolution with no image file to store.
🎥 Camera shake & motionGame cameras shake with noise so the motion feels handheld, and animators use it to add small movements to idle characters, flames, and flags.

Design Challenges

Use the World Builder Lab. Record the seed and every setting so someone else can recreate your result exactly.

1. Archipelago

Make a map that is at least 60% water with five or more separate islands. (Hint: the Water readout and the sea level slider.)

2. Smooth vs. rugged

Find settings for rolling farmland and settings for jagged alpine peaks on the same seed. Which two sliders made the biggest difference?

3. Seed swap

Pick a seed and describe your world in three sentences without naming the seed. Can a partner find the seed from a list of five?

4. Invent a material

Sketch a material not in the gallery (lava, camouflage, a leopard's spots). Describe the rule that turns the noise number into a color.

Check Yourself

Answer, then press Check. A hint appears if you are not quite there.

Easy1. In Perlin noise, neighboring points have completely unrelated values. True or false?

That describes white noise. Perlin noise is smooth, so nearby points have similar values.

Easy2. Value noise stores a random height at each lattice point. What does Perlin noise store there instead?

Look back at Part 2: you dragged purple handles that changed the steepness at each whole number.

Easy3. What is the value of 1D Perlin noise at exactly x = 7, no matter what the slopes are?

At a whole number, t = 0. The left term g₀ · t is 0, and fade(0) = 0 means the blend uses only that left term.

Medium4. What does adding more octaves do?

Each new octave has a higher frequency (bumps closer together) and a smaller amplitude (shorter bumps).

Medium5. With persistence 0.5, octave 1 has amplitude 1.0. What is the largest possible combined amplitude of 3 octaves?

Add the amplitudes: 1.0 + 0.5 + 0.25.

Medium6. From Part 7: slopes[3] = 1 and slopes[4] = −1. What is noise(3.5)? (fade(0.5) = 0.5)

t = 0.5. left = 1 × 0.5 = 0.5. right = −1 × (0.5 − 1) = 0.5. The blend of 0.5 and 0.5 is…

Medium7. Two players type the same seed and the same settings on different computers. What do they get?

The "random" slopes come from a formula that starts with the seed. The same starting number always produces the same list.

Challenge8. What goes wrong if you blend the corner values with a plain linear blend instead of a fade curve?

Switch Part 2 to "Linear" and look at the curve at each whole number. The slope jumps instead of changing smoothly.

Turn the concept into generative art

Signal Garden combines smooth noise, sine waves, color theory, live controls, PNG export, tutorials, and creative challenges.

Download Creative Coding Pack