Files
sunny9898/task8/_ref/noc-examples-processing-master/introduction/Gaussian2/Gaussian2.pde
louiscklaw 5637fbf94f update,
2025-02-01 02:07:58 +08:00

46 lines
1.1 KiB
Plaintext

// The Nature of Code
// Daniel Shiffman
// http://natureofcode.com
void setup() {
size(200,200);
background(0);
}
void draw() {
//create an alpha blended background
fill(0,1);
rect(0,0,width,height);
//get 3 gaussian random numbers w/ mean of 0 and standard deviation of 1.0
float r = randomGaussian();
float g = randomGaussian();
float b = randomGaussian();
//define standard deviation and mean
float sd = 100; float mean = 100;
//scale by standard deviation and mean
//also constrain to between (0,255) since we are dealing with color
r = constrain((r * sd) + mean,0,255);
//repeat for g & b
sd = 20; mean = 200;
g = constrain((g * sd) + mean,0,255);
sd = 50; mean = 0;
b = constrain((b * sd) + mean,0,255);
//get more gaussian numbers, this time for position
float xloc = randomGaussian();
float yloc = randomGaussian();
sd = width/10;
mean = width/2;
xloc = ( xloc * sd ) + mean;
yloc = ( yloc * sd ) + mean;
//draw an ellipse with gaussian generated color and position
noStroke();
fill(r,g,b);
ellipse(xloc,yloc,8,8);
}