Source code: spinning_image
The rotating thing is a little tricky. You have to use the translate command. when you translate processing changes the location that it uses as 0, 0 (usually the upper left corner). Then you place an image relative to the new center, and rotate around this center point.The confusing thing is translate will mess everything else up after it, so you need to use the pushMatrix (to set a benchmark of how everything is set up beforehand) and popMatrix (to reset it to how it was after you translate).
PImage person;
float ballx = 0;
float bally = 200;
float speedx = 2.7;
float speedy = 1.2;
int frame = 0;
float slowcounter = 0.0;
float r = .1;
void setup(){
person = loadImage("person1.png"); // put the image in each image variable
size(600, 400);
}
void draw (){
background (50);
smooth();
ballx = ballx + speedx;
bally = bally + speedy;
if ((ballx > width) || (ballx < 0)) {
speedx = speedx * -1;
}
if ((bally > height) || (bally < 0)) {
speedy = speedy * -1;
}
r += .01;
pushMatrix(); // save the current state
translate (ballx, bally); // the new center is the ball location
rotate(r); // rotates the translation
imageMode(CENTER); // means the image will be centered
image(person, 0, 0); // the 0, 0 are the center of the new translated area
popMatrix(); // resets things to how they were before translate
}
Built with Processing