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 › Rotating an Image
Page Index Toggle Pages: 1
Rotating an Image (Read 657 times)
Rotating an Image
Oct 23rd, 2009, 7:13pm
 
Hey Guys, I'm new to processing and am trying to rotate an image in place (i.e. the spinning rainbow circle of death for Macs when you load something). For some reason it spins around the coordinate (0,0) instead.  Can someone please help me change my code so that I can control how much the image rotates according to the angle I give it?

PImage a;

float x,y;
float r;

void setup(){
 size(800,800);
 a = loadImage("Arrow.jpg");
 x = y = width/2;
 r = 0;}
 
void draw(){
 background(255);
 translate(x,y,0);
 rotate(r);
 imageMode(CENTER);
 image(a,x,y,100,100);
 r = r + 0.01;}
Re: Rotating an Image
Reply #1 - Oct 23rd, 2009, 9:22pm
 
First, you'll need to use the 2D version of translate:

translate(x,y);

Giving it three coordinates messes things up because you are not using a 3D renderer.

Now you will notice that the image rotates around (x,y) but moves along a circle touching the corners of your sketch display.

To fix this, you need to put the image at coordinates 0,0:

image(a,0,0,100,100);

This is necessary because rotate(r) always rotates around (0,0).  The translate(x,y) is applied after the rotation, thus making it look like as if it was rotated around (x,y).
Re: Rotating an Image
Reply #2 - Oct 23rd, 2009, 9:30pm
 
Grin THANK YOU SO MUCH!!! Arghh, I can't believe changing something so minute can make my life so much less stressful.
Page Index Toggle Pages: 1