Skip to content

Language Settings

Noise Wave

Using Perlin Noise to generate a wave-like pattern. Original by Daniel Shiffman.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
let yoff = 0.0; // 2nd dimension of perlin noise
function setup() {
  createCanvas(710, 400);
}
function draw() {
  background(51);
  fill(255);
  // We are going to draw a polygon out of the wave points
  beginShape();
  let xoff = 0; // Option #1: 2D Noise
  // let xoff = yoff; // Option #2: 1D Noise
  // Iterate over horizontal pixels
  for (let x = 0; x <= width; x += 10) {
    // Calculate a y value according to noise, map to
    // Option #1: 2D Noise
    let y = map(noise(xoff, yoff), 0, 1, 200, 300);
    // Option #2: 1D Noise
    // let y = map(noise(xoff), 0, 1, 200,300);
    // Set the vertex
    vertex(x, y);
    // Increment x dimension for noise
    xoff += 0.05;
  }
  // increment y dimension for noise
  yoff += 0.01;
  vertex(width, height);
  vertex(0, height);
  endShape(CLOSE);
}
X

creative commons license