topical media & game development
graphic-processing-algorithm-Ch06-p128-p128.pde / pde
PImage leafImage; //define an image object
PImage myBackImage; //define an image object
void setup(){
leafImage = loadImage("maple_leaf.gif"); //load it
myBackImage = loadImage("ground.jpg"); //load it
size(myBackImage.width,myBackImage.height);
}
int x, y; //the location of the cursor
void draw(){
image(myBackImage,0,0); //draw the ground
image(leafImage,x,y); //then the leaf
x += int(random(-5,5)); //random tremblings
y += int(random(-5,5));
}
void mouseDragged(){
x = mouseX-(leafImage.width/2); //move the cursor
y = mouseY-(leafImage.height/2);
}
(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.