topical media & game development
graphic-processing-learning-13-example-13-2-example-13-2.pde / pde
// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com
// Example 13-2: Random number distribution
// An array to keep track of how often random numbers are picked.
float[] randomCounts;
void setup() {
size(200,200);
randomCounts = new float[20];
}
void draw() {
background(255);
// Pick a random number and increase the count
int index = int(random(randomCounts.length));
randomCounts[index] ++ ;
// Draw a rectangle to graph results
stroke(0);
fill(175);
for (int x = 0; x < randomCounts.length; x ++ ) {
rect(x*10,0,9,randomCounts[x]);
}
}
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.