We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
zoom to center (Read 1885 times)
zoom to center
Jun 2nd, 2010, 1:02pm
 
hi, i'm very new to processing and I'm trying to make a zoom with scale().
when I use scale(2) the sketch makes a zoom to the upper left corner.

How can make a zoom to the center of the sketch?

thanks a lot!
Re: zoom to center
Reply #1 - Jun 2nd, 2010, 1:53pm
 
You could use translate, like in the example below...

Code:
float scaler = 1;

void setup() {
 size(500,500);
 smooth();
 noStroke();
}

void draw() {

 translate(width/2,height/2); // use translate around scale
 scale(scaler);
 translate(-width/2,-height/2); // to scale from the center

 background(255);
 fill(0);
 ellipse(140,140,140,140);
 ellipse(250,200,200,200);
 ellipse(400,200,70,70);
 ellipse(230,320,20,20);
 ellipse(400,400,50,50);
 fill(255);
 ellipse(width/2,height/2,30,30);
 fill(255,0,0);
 ellipse(width/2,height/2,1,1);
}

void keyPressed() {
 if (key == 'z') {scaler -= 0.1;} // smaller
 if (key == 'x') {scaler += 0.1;} // bigger
 if (key == 'c') {scaler = 1;} // reset scale
}
Re: zoom to center
Reply #2 - Jun 3rd, 2010, 11:05pm
 
Hi AmnonP5,

That has indeed worked!

Thanks, very clear.

Cheers
Page Index Toggle Pages: 1