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 › using rotate and not using rotate
Page Index Toggle Pages: 1
using rotate and not using rotate (Read 538 times)
using rotate and not using rotate
Nov 9th, 2006, 6:07pm
 
I love Processing.  This is my first program in Processing and it is really a great language to program in.

I have a simple program below that rotates an image and slows down the rotation and then stops it.

When I stop the image I want to put some text in the bottom left corner of the screen. Right now the text shows up in the center rotated (because of my rotation and translation).  How do I un-rotate and translate the text only?

Thanks,
Mike


PImage img;
PImage arrow;
PFont font;
float t;
float decelerate;
float angle;
float stop;
int a;

void setup()  
{  
 size(640,740);
 img  = loadImage("boys-circle-spin.png");
 arrow = loadImage("arrow.jpg"); // Load the images into the program
 t=random(1);
 decelerate=-0.6;
 angle=0.1;
 font = loadFont("ComicSansMS-48.vlw");
 textFont(font);
}  

void draw(){  
 background(0);
 image(arrow, 280, 640, arrow.width/6, arrow.height/6);//load arrow
 angle=angle +  exp (decelerate*t);  // decay.
 translate(320,320);  //rotate the picture of the boys around the center
 rotate(angle);  
 image(img, -img.width/2, -img.height/2);
 t=t+0.1;  
 
 if (t >=10){       // stuff to determine where the wheel stopped
 stop=angle/6.28;
 int a = floor(stop);
 stop = stop - a;
 println(angle);
 println(stop);
 println(t) ;
   noLoop();
      if((stop > .3) && (stop < .6)) {
      text("Daniel", 0, 0);   //this text shows up rotated
      fill(0, 102, 153);
      }else if ((stop > .6) && (stop < .95)){
       text("Joey", 0, 0);   //this text shows up rotated
      }else {text("David", 0, 0);  //this text shows up rotated
   }
 }  
   

 }


void mousePressed(){  
 decelerate = -1; //speed up the deceleration if the mouse is pressed
}
Re: using rotate and not using rotate
Reply #1 - Nov 9th, 2006, 6:28pm
 
What you need is pushMatrix() and popMartix().

What these do is save the camera position, and then restore that saved position at a later date.

so for example you put pushMatrix(); at the start before you do the rotation on your image, then after drawing the image you put popMatrix(); and the camera will return to its original position, i.e. to the settings where (0,height) == bottom left corner.
Page Index Toggle Pages: 1