Code

p5.js

Perlin Noise

Intermediatenoise(x, y, z) produces smooth organic randomness. Used here for undulating terrain lines and a noise-field that steers particle worms. p5.js Docs

p.noiseSeed(42);
p.noiseDetail(3, 0.5);

// Terrain: sample noise along X, offset by row + time
for (let x = 0; x < p.width; x += 4) {
  const n = p.noise(x * 0.006, row * 0.4 + zOff);
  const y = yBase + (n - 0.5) * 60;
  p.vertex(x, y);
}

// Noise-field worm: angle = noise(xOff, yOff, zOff)
const angle = p.noise(w.xOff, w.yOff, zOff) * p.TWO_PI * 4;
w.x += Math.cos(angle) * 2;
w.y += Math.sin(angle) * 1.5;
w.xOff += 0.004;  // advance through noise space

// Advance time slice each frame
zOff += 0.004;