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 & HelpPrograms › Rotate Image around Center
Page Index Toggle Pages: 1
Rotate Image around Center (Read 3507 times)
Rotate Image around Center
Sep 2nd, 2009, 9:34am
 
Hey there

I'm new here and i have a little question: Is it possible to rotate an image around it's center? If i do something like...

Code:
float counter;
PImage img;

void setup()
{
 counter=0.0;
 size(300,300);
 img=loadImage("brownplane.png");
}

void draw()
{
 background(0);
 counter++;
 translate(width/2-img.width/2, height/2-img.height/2);
 rotate(counter*TWO_PI/360);
 // rect(-26, -26, 52, 52);
 image(img,0,0);
}


...it ends up rotating around it's upper left corner. Is it possible to define something like a pivot? I couldn't find anything in the documentation so far.

Thanks in advance!
Oliver
Re: Rotate Image around Center
Reply #1 - Sep 2nd, 2009, 9:44am
 
I wish I was paid € 1 each time I see this question. I would be rich now... (well, not so much, actually).

Should go in a FAQ...

You weren't so far, you just have to translate to half the image size (or to the point you want to rotate around) after the rotation:

 translate(width/2, height/2);
 rotate(counter*TWO_PI/360);
 translate(-img.width/2, -img.height/2);
Re: Rotate Image around Center
Reply #2 - Sep 2nd, 2009, 9:55am
 
Quote:
I wish I was paid € 1 each time I see this question.


I tried to search the forum for "image", "center" and "rotate", but didn't get any results. Hmmm... whatever, thanks a lot!
Re: Rotate Image around Center
Reply #3 - Sep 2nd, 2009, 10:21am
 
Don't worry, it wasn't a reproach, more like a hint for the FAQ (or reference).
The problem being quite generic, it is hard to search (unlike a rare function name).

Note: for some reason (performance!), search is limited to week-old messages. You have to remember to set it to (all posts). And even so, no obvious answer.
Page Index Toggle Pages: 1