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
-- from CENTER (Read 682 times)
-- from CENTER
Jan 4th, 2007, 2:54pm
 
Hi,
I've an image, that scales itself from 100% to n% by some events.

the image inside the class is drawn by:

[...]
imageMode(CORNERS);
image(img, x1, y1, x2, y2);
[...]

(must be in imageMode --> CORNERS because inside the class is used for other methods)

how can I rotate from his center keep the proper "scale" and "position"?


thanks for suggests.
Re: -- from CENTER
Reply #1 - Jan 4th, 2007, 5:28pm
 
Perhaps it would be easier to think about it as if your image were always drawn centered at the origin.  Then position with translations, and rotate and scale however desired.  Something like:

Quote:



PImage img;
float rottheta = 0f; // rotation animation
float scatheta = 0f; // scaling animation

// some variables to set position/size of image
int x1 = 50;
int y1 = 50;
int x2 = 150;
int y2 = 150;
int xw = x2-x1+1;
int yh = y2-y1+1;

void setup() {
 size(200,200);
 img = loadImage("eames.jpg");
 imageMode(CORNERS);
}

void draw() {
 background(0);
 // go to "center" of image
 translate(x1+xw/2, y1+yh/2);
 // perform rotation from "there"
 rotate(rottheta+=0.01f);
 // perform scaling (either before or after rotation, doesn't matter in this case)
 scale(sin(scatheta+=0.01f));
 // draw image with corners as if its center were at 0,0
 image(img, -xw/2, -yh/2, xw/2, yh/2);  
}



Re: -- from CENTER
Reply #2 - Jan 4th, 2007, 6:52pm
 
yessss! of course! ... thanks a lot. Smiley


(my temporary solution was to rotate from topLeft corner, and then move the origin of "bounding-box" of rotated image, adding the sin and cos for each coord of the proper angle, proportionally to actual dimension of image)
Page Index Toggle Pages: 1