import java.awt.*;
import java.applet.*;
import java.util.*;

public class TURTLE02 extends Applet implements Runnable{

  Dimension d;
  Image offI;
  Color dark = new Color(30,120,30);
  Color light = new Color(255,160,40);
  Color colors[] = { Color.red, Color.yellow, Color.green, Color.cyan,
    new Color(125,125,125), Color.magenta, new Color(99,50,255), Color.orange, Color.pink };
  Random r;
  int cycle, inc;
  int body, fleg, bleg;
  Thread tt;

  public void init(){
    d = getSize();
    r = new Random();
    fleg=0;
    bleg=0;
    body=0;
    offI = createImage(d.width, d.height);
    tt = new Thread(this);
    tt.start();
  }

  public void run(){
     while(true){
       cycle++;
       cycle%=2;
       inc++;
       inc%=3;
       if(inc%3==0) fleg+=12;
       else if(inc%3==1) bleg+=12;
       else body+=12;
       if(body>500){
         body=0;
         fleg=0;
         bleg=0;
       }
       repaint(); 
       try{ 
         Thread.sleep(150); 
       }catch(InterruptedException ie){ } 
     } 
  }

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

  public void paint(Graphics g){
    Graphics og = offI.getGraphics();
    og.setColor(Color.yellow);
    og.fillRect(0,0,d.width,d.height);
    og.setFont(new Font("Courier",Font.BOLD,60));
    og.setColor(Color.black);
    og.drawString("blackturtle.us",80,360);
    int endPT=6;
    int start=body+40;
    for(int yy=0; yy<4; yy++){
      for(int xx=0; xx<endPT; xx++){
        int pick = Math.abs(r.nextInt()%colors.length);
        //og.setColor(colors[pick]);
        if(cycle==0) og.fillRect(start+xx*20,270-yy*20,18,18);
        else og.fillOval(start+xx*20,270-yy*20,18,18);
      }
      start+=10;
      endPT--;
    }
     //tail
    int c[] = {body+42,body+55,body+40,body+22,body+32,body+42 };
    int d[] = {291,291,296,300,296,291 };
    Polygon tail = new Polygon(c,d,c.length);
    og.fillPolygon(tail);
    //back leg
    int bx[]={bleg+68,bleg+78,bleg+88,bleg+58,bleg+68};
    int by[]={291,291,310,310,291};
    Polygon backleg=new Polygon(bx,by,bx.length);
    og.fillPolygon(backleg);    
    //front leg
    int fx[]={fleg+118,fleg+128,fleg+138,fleg+108,fleg+118};
    int fy[]={291,291,310,310,291};
    Polygon frontleg=new Polygon(fx,fy,fx.length);
    og.fillPolygon(frontleg);    
    //head
    int hx[]={body+140,body+165,body+175,body+190,body+200,body+190,body+175,body+165,body+150,body+140};
    int hy[]={291,291,270,270,291,305,305,300,300,291};
    Polygon head=new Polygon(hx,hy,hx.length);
    og.fillPolygon(head);    
    og.setColor(Color.yellow);
    og.fillOval(body+186,280,5,5);
    og.drawLine(body+195,300,body+185,295);
    g.drawImage(offI, 0, 0, this);
    og.dispose();
  }
}

//<applet code=TURTLE02.class height=520 width=648></applet>
