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 in/ zoom out in PApplet (Read 3332 times)
zoom in/ zoom out in PApplet
Aug 10th, 2006, 7:18am
 
Hi,

I have a PApplet which contains cube or lets say any chart or bar graph, now i want to add a functionality for zoom out, that is, if i click on cube or chart or any thing in the PApplet, it should get enlarge.

So can any body help me on this ?

regards
Rajesh

Re: zoom in/ zoom out in PApplet
Reply #1 - Aug 10th, 2006, 9:06am
 
You are looking for scale(). Take a look at this example:

Quote:


void setup(){
size(400, 400, P3D);
fill(125,125);
}
void draw(){
 background(255);
translate(width/2, height/2);
scale(mouseX,mouseX,mouseX);
box(20, 20, 20);
}

Re: zoom in/ zoom out in PApplet
Reply #2 - Aug 10th, 2006, 1:16pm
 
thanks eskimoblood
but it didnt solved my problem,
actualy i m looking for a funtionality that if i click on cube or chart or any thing in the PApplet, it should get enlarge.

regards
rajesh
Re: zoom in/ zoom out in PApplet
Reply #3 - Aug 14th, 2006, 7:10am
 
Well the question isn't totally clear, but if I understand what you're asking then what you need to do is something like this:

Code:


void mouseReleased() {
if (chart.contains(mouseX, mouseY)) {
chart.setEnlarged(true);
}
}

void draw() {
pushMatrix();
if (chart.isEnlarged()) {
scale(10);
}
chart.draw();
popMatrix();
}


The above code assumes that you have an class which the variable chart is an instance of. That class would have a method contains(int x, int y) which would return whether or not that position was in the bounds of the object, as well as the methods setEnlarged(boolean b) and isEnlarged() which would probably just flip an internal boolean variable.

Finally the draw method would check if the chart was enlarged, and if it was scale before drawing it. The pushMatrix() and popMatrix() are to ensure that it doesn't scale everything, but just the chart in question.
Page Index Toggle Pages: 1