When I press a key, I want the entire screen that is currently drawn to animate through a 90 degree rotation. That is, I want to watch the screen rotate; I do not want it simply to jump to the rotated state.
However, I want to do all of the rotation/animating in a method other than the draw method (for instance, in the keyPressed() method).
I can make things rotate using the draw() method, and I can have keyPressed() affect the rotation, but this is not what I am looking for:
int angle;
void setup() {
size(200, 200);
angle = 0;
}
void draw() {
background(0);
if(angle < 90) {
angle++;
}
translate(width/2,height/2);
rotate(radians(angle));
translate(-width/2,-height/2);
ellipse(width/2, height/2, 50, 30);
}
void keyPressed() {
angle = 0;
}
I want the ellipse to start out horizontal, and then when I press a button I want to watch it rotate to the vertical.
If I use a for/while loop in the keyPressed() method, it goes much to quickly to actually see the animation:
int angle;
void setup() {
size(200, 200);
angle = 0;
background(0);
ellipse(width/2, height/2, 50, 30);
}
void draw() {
}
void keyPressed() {
while (angle < 90) {
background(0);
translate(width/2, height/2);
rotate(radians(1)); //since the effect is cumulative