From c41905d3f1d9b4f7482e337e847f3c4218f89e0f Mon Sep 17 00:00:00 2001 From: Daniel Shiffman Date: Wed, 6 Mar 2013 16:52:08 -0500 Subject: [PATCH] adding a new example for randomGaussian --- .../Math/RandomGaussian/RandomGaussian.pde | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 java/examples/Basics/Math/RandomGaussian/RandomGaussian.pde diff --git a/java/examples/Basics/Math/RandomGaussian/RandomGaussian.pde b/java/examples/Basics/Math/RandomGaussian/RandomGaussian.pde new file mode 100644 index 000000000..d71501dba --- /dev/null +++ b/java/examples/Basics/Math/RandomGaussian/RandomGaussian.pde @@ -0,0 +1,28 @@ +/** + * Random Gaussian. + * + * This sketch draws ellipses with x and y locations tied to a gaussian distribution of random numbers. + */ + +void setup() { + size(640, 360); + background(0); +} + +void draw() { + + // Get a gaussian random number w/ mean of 0 and standard deviation of 1.0 + float val = randomGaussian(); + + float sd = 60; // Define a standard deviation + float mean = width/2; // Define a mean value (middle of the screen along the x-axis) + float x = ( val * sd ) + mean; // Scale the gaussian random number by standard deviation and mean + + noStroke(); + fill(255, 10); + noStroke(); + ellipse(x, height/2, 32, 32); // Draw an ellipse at our "normal" random location +} + + +