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
Rotate an image (Read 2159 times)
Rotate an image
Oct 15th, 2008, 10:08am
 
Is it possible to load an external image and then have that image rotated a set amount on a mouse click?

E.g. 1 click rotates it 90 deg, 2 clicks 180 deg etc

I am new to all this and am slightly bamboozled.



Re: Rotate an image
Reply #1 - Oct 15th, 2008, 5:38pm
 
Quite simple: load image into a variable of type PImage, paint it, then call mouseClicked() to increment a rotation amount.

PImage pim;
float rot=0;
void setup(){
 pim = loadImage("http://processing.org/img/processing_beta_cover.gif");
}
void draw(){
 background(255);
 translate(width/2, height/2);
 rotate(rot);
 image(pim,-pim.width/2,-pim.height/2);
}
void mouseClicked(){
 rot+=PI/2;
}
Re: Rotate an image
Reply #2 - Oct 16th, 2008, 8:35am
 
thankin' ye!
Re: Rotate an image
Reply #3 - Oct 24th, 2008, 9:55am
 
I have a similar problem, I need to move an image but in a 3d sense, I have been through the References and I don't know what to pick. Right now I have a disc, with a smaller one inside which I would like to animate, moving it left and round to the front, how would I achieve this?


// Location of moving circle to start with (stationary)
int circleX = 300;
int circleY = 241;

//size of page
void setup() {
 size(600,600);
 smooth();


 // Disc
fill(255);
ellipse(300,250,160,30);

 // Moving circle shape size and colour details
 stroke(0);
 fill(122, 222, 33);
 ellipse(circleX,circleY,22,6);
}
Page Index Toggle Pages: 1