Double Random

Double Random by Ira Greenberg.

Using two random() calls and the point() function to create an irregular sawtooth line.


int totalPts = 300;
float steps = totalPts + 1;
  
void setup() {
  size(640, 360);
  stroke(255);
  frameRate(1);
} 

void draw() {
  background(0);
  float rand = 0;
  for  (int i = 1; i < steps; i++) {
    point( (width/steps) * i, (height/2) + random(-rand, rand) );
    rand += random(-5, 5);
  }
}

Functions Used

stroke()

Sets the color used to draw lines and borders around shapes

Learn More
size()

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

Learn More
point()

Draws a point, a coordinate in space at the dimension of one pixel

Learn More
setup()

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

Learn More
frameRate

The system variable frameRate contains the approximate frame rate of a running sketch

Learn More
random()

Generates random numbers

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
background()

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

Learn More