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.
IndexProgramming Questions & HelpSyntax Questions › scale and translate
Page Index Toggle Pages: 1
scale and translate (Read 409 times)
scale and translate
Apr 9th, 2008, 1:52pm
 
hey,
when i scale images they r always scaledm anchored to the top left corner, can i change the scale mode to center or something?
if not
if i scale an image by the factor "n", how must the correct translate function with "n" as a parameter be called to have the image grow to its center?
Re: scale and translate
Reply #1 - Apr 9th, 2008, 4:34pm
 
translate the image so its centre is at the origin before scaling. (and move it back afterwards)

Re: scale and translate
Reply #2 - Apr 9th, 2008, 5:57pm
 
p3d/opengl:

 pushMatrix();
 translate( posx, posy );
 scale( scaleFactor );
 image( img, 0, 0 );
 popMatrix();

 posx = (width/2) - ((img.width/2)*scaleFactor);
 posy = (height/2) - ((img.height/2)*scaleFactor);

and like koogs said, its important to do scaling *After* translation
Re: scale and translate
Reply #3 - Apr 9th, 2008, 6:11pm
 
thank you,
heres my code

Quote:


PImage img;
float v = 1.0;
float inc = 0.005;

void setup(){
 size(400,400);
 background(255);
 img = loadImage("1.gif");
}

void draw(){
 float n = noise(v) * 2.5;
fill(255,5);
rect(0,0,width,height);
tint(0,255-n*100,n*100,255);
 //from here
translate(mouseX,mouseY);
translate(-n*img.width/2,-n*img.height/2);
scale(n);
image(img,0,0);
 //to here

v += inc;

}


Page Index Toggle Pages: 1