This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Pyry

By: a guest on Feb 21st, 2009  |  syntax: Java  |  size: 0.64 KB  |  views: 124  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. PImage teddy;
  2.  
  3. float xpos;
  4. float ypos;
  5. float drag = 30.0;
  6.  
  7. void setup()
  8. {
  9.   size(200,200);
  10.   teddy = loadImage("teddy.gif");
  11.   xpos = width/2;
  12.   ypos = height/2;
  13.   frameRate(60);
  14. }
  15.  
  16. void draw()
  17. {
  18.   background(102);
  19.  
  20.   float difx = mouseX - xpos-teddy.width/2;
  21.   if(abs(difx) > 1.0) {
  22.     xpos = xpos + difx/drag;
  23.     xpos = constrain(xpos, 0, width-teddy.width);
  24.   }  
  25.  
  26.   float dify = mouseY - ypos-teddy.height/2;
  27.   if(abs(dify) > 1.0) {
  28.     ypos = ypos + dify/drag;
  29.     ypos = constrain(ypos, 0, height-teddy.height);
  30.   }  
  31.  
  32.   // Display the sprite at the position xpos, ypos
  33.   image(teddy, xpos, ypos);
  34. }
clone this paste RAW Paste Data