/* ROTATE.java - Rotates an image.
   Created by Randy McGirr 2011
*/
import java.awt.*;
import java.awt.geom.*;
import java.applet.*;
import java.util.*;

public class ROTATE extends Applet implements Runnable{
Dimension d;
Image offI;
Image turtle;
AffineTransform trans;
int currentAngle, w, h;
Rectangle rect;
Thread tt;
Color bg;

public void init(){
d = getSize();
bg=new Color(0,0,255);
offI=createImage(d.width,d.height);
turtle = getImage(getDocumentBase(), "turtle.jpg");
rect=this.getBounds();
currentAngle=0;
w=20;
h=20;
//turtle=turtle.getScaledInstance(w,h,Image.SCALE_SMOOTH);
trans=new AffineTransform();
tt = new Thread(this);
tt.start();
}

public void run(){
int pause=80;
while(true){
repaint();
try{
Thread.sleep(pause);
}catch(InterruptedException ie){
}
w+=1;
h+=1;
//turtle=turtle.getScaledInstance(w,h,Image.SCALE_SMOOTH);
trans.setToTranslation((rect.width-turtle.getWidth(this))/2,(rect.height-turtle.getHeight(this))/2);
trans.rotate(Math.toRadians(currentAngle), turtle.getWidth(this)/2, turtle.getHeight(this)/2);
currentAngle+=5;
if(currentAngle>360){
 pause=1500;
 currentAngle=0;
 }
 else pause=80;
}
}

public void update(Graphics g){
paint(g);
}

public void paint(Graphics g){
Graphics2D offG = (Graphics2D)offI.getGraphics(); 
offG.setColor(bg);
offG.fillRect(0,0,d.width,d.height);
offG.drawImage(turtle,trans,this);
g.drawImage(offI,0,0,this);
}
}
//<applet code=ROTATE.class height=490 width=880></applet>