Skip to content

Language Settings

Random Gaussian

This sketch draws ellipses with x and y locations tied to a gaussian distribution of random numbers.

This example is ported from the Random Gaussian example on the Processing website

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  function setup() {
    createCanvas(720, 400);
    background(0);
  }
  
  function draw() {
  
    // Get a gaussian random number w/ mean of 0 and standard deviation of 1.0
    let val = randomGaussian();
  
    let sd = 60;                  // Define a standard deviation
    let mean = width/2;           // Define a mean value (middle of the screen along the x-axis)
    let x = ( val * sd ) + mean;  // Scale the gaussian random number by standard deviation and mean
  
    noStroke();
    fill(255, 10);
    ellipse(x, height/2, 32, 32);   // Draw an ellipse at our "normal" random location
  }
X

creative commons license