topical media & game development
graphic-processing-algorithm-Ch06-p130-Leaf.pde / pde
class Leaf {
int x, y; //the leaf's position
PImage picture; //an image object
int rate; //rate of waiting to be redrawn
Leaf(){ //constructor
x = int(random(width)); //get an initial location
y = int(random(height));
picture = loadImage("maple_leaf.gif"); //get the image
}
int k=0; //a counter
void draw() {
if(k==rate){ //if the counter is as the rate then draw
x += int(random(-5,5)); //random tremblings
y += int(random(-5,5));
k=0; //reset the counter
}
k++; //increate the counter; during every increment there is no draw
image(picture,x,y); //now draw the image
}
}
(C) Æliens
04/09/2009
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.