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 › PNG rotation, center point
Page Index Toggle Pages: 1
PNG rotation, center point? (Read 742 times)
PNG rotation, center point?
Mar 30th, 2009, 10:14am
 
Hi.

I have a PNG with a transparency that I'm loading as a PImage and trying to rotate. When I try that, though, the image rotates about a point seemingly a few hundred pixels above where I assume the center to be. I've tried imageMode(CENTER), but that didn't seem to do it. Here's a short sketch of me trying this with just the image on its own.

Code:
PImage wheel;

void setup() {
 size(300,300);
 wheel=loadImage("wheel.png");
}

void draw() {
 rotate(PI);
 image(wheel,150,150);
}


And here's the image:

...

Image looks fine, so I can't for the life of me see what this is.

edit: After looking at it further, it seems that rotate() rotates the image around the center of the program window when imageMode() is set to CORNER, and around the placed image center when imageMode() is set to CENTER. Does that sound right? If so, is there a way to set some sort of bounding box around the image or something, so it rotates around its own axis?
Re: PNG rotation, center point?
Reply #1 - Mar 30th, 2009, 1:51pm
 
You have to use a combination of translate and rotate. Search the forum, there are plenty examples of this.
In short, you translate to the point where the center of the shape/image must be, do the rotation, then translate back of the radius of the image.
Re: PNG rotation, center point?
Reply #2 - Mar 30th, 2009, 2:15pm
 
i hope i dont ruin PhiLhos pedagogic way of helping by showing some code... by the way, just rotating it by PI doesnt move it... you have to count it up. Hope it gets clearer. You should take a look at the rotate and translate examples they show what we were talking about :
http://processing.org/learning/basics/rotate.html and maybe look at
http://processing.org/reference/pushMatrix_.html cause you will need that as soon as you work with more then one object...




PImage wheel;
float r = 0;
void setup() {
 size(300,300);
 imageMode(CENTER);
 wheel=loadImage("wheel.png");
}

void draw() {
 background(255);
 
 rotate(r);
 image(wheel,0,0);

 r+=0.02;
}

Page Index Toggle Pages: 1