/** * Sprite (Teddy) * by James Patterson. * * Demonstrates loading and displaying a transparent GIF image. * * Created 27 January 2003. * Updated 8 July 2004 */ PImage teddy; float xpos; float ypos; float drag = 30.0; PImage bg; int a; void setup() { size(900,900); teddy = loadImage("feathergif.gif"); xpos = width/2; ypos = height/2; frameRate(60); size(900,900); frameRate(30); // The background image must be the same size as the parameters // into the size() method. In this program, the size of "milan_rubbish.jpg" // is 200 x 200 pixels. bg = loadImage("featherbg.jpg"); } void draw() { background(bg); a = (a + 1)%(width+32); stroke(226, 204, 0); line(0, a, width, a-26); line(0, a-6, width, a-32); float difx = mouseX - xpos-teddy.width/2; if(abs(difx) > 1.0) { xpos = xpos + difx/drag; xpos = constrain(xpos, 0, width-teddy.width); } float dify = mouseY - ypos-teddy.height/2; if(abs(dify) > 1.0) { ypos = ypos + dify/drag; ypos = constrain(ypos, 0, height-teddy.height); } // Display the sprite at the position xpos, ypos image(teddy, xpos, ypos); }