adding nature of code examples

This commit is contained in:
shiffman
2012-09-04 00:55:42 +00:00
parent 6e10c689e1
commit 6ad7b782d9
581 changed files with 229203 additions and 0 deletions
@@ -0,0 +1,34 @@
// Daniel Shiffman
// The Nature of Code
// http://www.shiffman.net/
int x,y;
void setup() {
size(200,200);
background(0);
smooth();
}
void draw() {
//create an alpha blended background
fill(0,1);
rect(0,0,width,height);
//calculate a probability between 0 and 100% based on mouseX location
float prob = (mouseX / (float) width);
//get a random floating point value between 0 and 1
float r = random(1);
//test the random value against the probability and trigger an event
if (r < prob) {
noStroke();
fill(255);
ellipse(x,y,10,10);
}
// X and Y walk through a grid
x = (x + 10) % width;
if (x == 0) y = (y + 10) % width;
}