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 › simple image rotation
Page Index Toggle Pages: 1
simple image rotation (Read 454 times)
simple image rotation
Apr 27th, 2006, 10:47pm
 
Hi, i'm just starting to learn processing (there should be a dummies/beginners sectione in this forum). I want to continously rotate the image ( i suppose there's no built-in rotate method, or yes?) but the code below draws just one rotation. What's wrong?
Thanks.


PImage img;
TransImage timage;
int currentImage;
private PImage temp;

class TransImage{
 PImage theImage;
 int w,h;
 
 public TransImage(PImage image){
   theImage=image;
   w=theImage.width;
   h=theImage.height;
   temp=new PImage(w,h);

 }
 void rotate(float angle){
   int xt,yt;
   int x,y;
   loadPixels();
   for(x=0;x<w*h;++x){
   temp.pixels[x]=theImage.pixels[x];
   }
   angle=-(angle*3.14)/180.0;
    for(x=0;x<h;++x)
   for(y=0;y<w;++y){
     xt=(int)((x-h/2)*cos(angle)+(y-w/2)*sin(angle));
     yt=(int)(-(x-h/2)*sin(angle)+(y-w/2)*cos(angle));
     xt=xt+h/2;
     yt=yt+w/2;
     if(xt>(h-1))   theImage.pixels[x*w+y]=color(0,0,0);
     else
     if(yt>(w-1)) theImage.pixels[x*w+y]=color(0,0,0);
     else
     if(xt<0) theImage.pixels[x*w+y]=color(0,0,0);
     else
     if(yt<0) theImage.pixels[x*w+y]=color(0,0,0);
     else
     theImage.pixels[x*w+y]=temp.pixels[xt*w+yt];
   }
    updatePixels();
   
 }
 
 public PImage getImage(){
   return theImage;
 }
}

void setup(){
 img=loadImage("clouds1.jpg");
 timage=new TransImage(img);
 size(256,256);
 background(0);
}

void draw(){
 background(0);
 timage.rotate((float)(frameCount%360));
 image(timage.getImage(),0,0);
 
 
}
Re: simple image rotation
Reply #1 - Apr 27th, 2006, 11:05pm
 
This should do what you want, without having to write your own functions Smiley

Code:
PImage img; 

void setup()
{
size(256,256);
img=loadImage("clouds1.jpg");
}

void draw()
{
background(0);
translate(width/2,height/2);
rotate(frameCount/360.0*TWO_PI);
translate(-img.width/2,-img.height/2);
image(img);
}
Re: simple image rotation
Reply #2 - Apr 27th, 2006, 11:25pm
 
I suspected that!!! Where are they documented???
Re: simple image rotation
Reply #3 - Apr 27th, 2006, 11:42pm
 
http://processing.org/reference/index_ext.html


Theres a menu at the top of this web page. Click Reference.

Also, you can view reference directly from Processing. It opens up the same info Smiley
Page Index Toggle Pages: 1