Skip to content

Commit 812f40c

Browse files
Random Gaussian Example Added
1 parent c89ef73 commit 812f40c

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* @name Random Gaussian
3+
* @frame 720,400
4+
* @description This sketch draws ellipses with x and y locations tied to a gaussian distribution of random numbers.
5+
* (ported from https://processing.org/examples/randomgaussian.html)
6+
*/
7+
8+
function setup() {
9+
createCanvas(720, 400);
10+
background(0);
11+
}
12+
13+
function draw() {
14+
15+
// Get a gaussian random number w/ mean of 0 and standard deviation of 1.0
16+
let val = randomGaussian();
17+
18+
let sd = 60; // Define a standard deviation
19+
let mean = width/2; // Define a mean value (middle of the screen along the x-axis)
20+
let x = ( val * sd ) + mean; // Scale the gaussian random number by standard deviation and mean
21+
22+
noStroke();
23+
fill(255, 10);
24+
ellipse(x, height/2, 32, 32); // Draw an ellipse at our "normal" random location
25+
}
26+

0 commit comments

Comments
 (0)