/* CDTURT.java - Producesturtle.
      Created by Randel McGirr
       Searles Valley, CA
       2012 
*/
                                  
import java.awt.*;
import java.applet.*;
import java.util.*;

public class CDTURT{
  String numbers[] = {"5", "4", "3", "2", "1", ""};
  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 scale, x, y, cnt;

  CDTURT(int w, int h, int s){
    r = new Random();
    scale=s;
    x=100;
    y=0;
    cnt=0;
  }

  public void draw(Graphics g){
    int endPT=6;
    int start=x+8*scale; // x replaces body
    //shells
    for(int yy=0; yy<4; yy++){ // 4 layers
      for(int xx=0; xx<endPT; xx++){  // each layer smaller than prev
        int pick = Math.abs(r.nextInt()%colors.length);
        g.setColor(colors[pick]);
        g.fillRect(start+xx*scale*4,y+scale*24-yy*scale*4,scale*4-2,scale*4-2);
      }
      start+=2*scale;
      endPT--;
    }
     //tail
    int tx=x+40;
    int c[] = {tx+8*scale,tx+10*scale,tx+8*scale,tx+4*scale,tx+6*scale,tx+8*scale }; // x replaces body
    int d[] = {y+scale*28,y+scale*28,y+scale*29,y+scale*30,y+scale*28,y+scale*28 };
    Polygon tail = new Polygon(c,d,c.length);
    g.fillPolygon(tail);
    //back leg
    int bleg=x+scale;
    int bx[]={bleg+13*scale,bleg+15*scale,bleg+17*scale,bleg+11*scale,bleg+13*scale};
    int by[]={y+scale*28,y+scale*28,y+scale*32,y+scale*32,y+scale*28};
    Polygon backleg=new Polygon(bx,by,bx.length);
    g.fillPolygon(backleg);    
    //front leg
    int fleg=bleg+scale*9;
    int fx[]={fleg+13*scale,fleg+15*scale,fleg+17*scale,fleg+11*scale,fleg+13*scale};
    int fy[]={y+scale*28,y+scale*28,y+scale*32,y+scale*32,y+scale*28};
    Polygon frontleg=new Polygon(fx,fy,fx.length);
    g.fillPolygon(frontleg);    
    //head
    int hx[]={x+28*scale,x+33*scale,x+35*scale,x+38*scale,x+40*scale,x+38*scale,x+35*scale,x+33*scale,x+30*scale,x+28*scale};
    int hy[]={y+scale*28,y+scale*28,y+scale*24,y+scale*24,y+scale*28,y+scale*31,y+scale*31,y+scale*30,y+scale*30,y+scale*28};
    Polygon head=new Polygon(hx,hy,hx.length);
    g.fillPolygon(head);    
    g.setColor(Color.black);
    g.fillOval(x+scale*37,y+scale*26,scale+1,scale+1);
    g.drawLine(x+scale*39,y+scale*30,x+scale*37,y+scale*29);
    //numbers
    g.setColor(Color.black);
    g.setFont(new Font("Courier", Font.BOLD, 400));
    g.drawString(numbers[cnt], 380, 530);
    cnt++;
    cnt%=6;
  }
}

//<applet code=CDTURT.class height=200 width=380></applet>
