Noise Wave

Noise Wave by Daniel Shiffman.

Using Perlin Noise to generate a wave-like pattern.


float yoff = 0.0;        // 2nd dimension of perlin noise

void setup() {
  size(640, 360);
}

void draw() {
  background(51);

  fill(255);
  // We are going to draw a polygon out of the wave points
  beginShape(); 
  
  float xoff = 0;       // Option #1: 2D Noise
  // float xoff = yoff; // Option #2: 1D Noise
  
  // Iterate over horizontal pixels
  for (float x = 0; x <= width; x += 10) {
    // Calculate a y value according to noise, map to 
    float y = map(noise(xoff, yoff), 0, 1, 200,300); // Option #1: 2D Noise
    // float y = map(noise(xoff), 0, 1, 200,300);    // Option #2: 1D Noise
    
    // 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);
}

Functions Used

fill()

Sets the color used to fill shapes

Learn More
size()

Defines the dimension of the display window width and height in units of pixels

Learn More
vertex()

All shapes are constructed by connecting a series of vertices

Learn More
beginShape()

Using the beginShape() and endShape() functions allow creating more complex forms

Learn More
setup()

The setup() function is run once, when the program starts

Learn More
map()

Re-maps a number from one range to another

Learn More
draw()

Called directly after setup(), the draw() function continuously executes the lines of code contained inside its block until the program is stopped or noLoop() is called

Learn More
noise()

Returns the Perlin noise value at specified coordinates

Learn More
endShape()

The endShape() function is the companion to beginShape() and may only be called after beginShape()

Learn More
background()

The background() function sets the color used for the background of the Processing window

Learn More