Scale image using mouseWheel

edited October 2013 in How To...

Hi all!

I'm new to processing and trying to scale image using Mouse wheel. Basically, I get the value of e, but it doesn't seem to be global variable so draw function cannot use it to scale image. Please help me to solve this problem!

PImage img; float e = 0.0;

void setup() { size (500, 500); img =loadImage ("img.png"); frameRate (24); }

void mouseWheel(MouseEvent event) { float e = event.getAmount(); println(e); }

void draw () { background (255); translate (0, 0); scale (e); image(img, 50, 50); }

Tagged:

Answers

  • I make something quick like that, I think you need a var to record your scale before use

    PImage img; float e = 0.0;
    
    void setup() { 
    size (500, 500); 
    img =loadImage ("img.jpg"); 
    frameRate (5); 
    }
    
    void mouseWheel(MouseEvent event) { 
    float e = event.getAmount();
    scaleImg += e *.01 ;
    }
    
    float scaleImg = 1 ;
    
    void draw () {
    println(scaleImg) ;
    background (255); 
    translate (0, 0); 
    scale (scaleImg); 
    image(img, 50, 50); 
    }
    
  • Thanks a lot! :)

Sign In or Register to comment.