import java.awt.Graphics; 
import java.awt.Color;
import java.applet.Applet;

public class ShrinkApplet extends Applet implements Runnable {
  Thread t;
  int[] xS = { 30, 30, 270, 230, 170 };  // 開始多角形の頂点のx座標
  int[] yS = { 30, 240, 220, 40, 110 };  //                   y座標     
  int xE = 150;  // 収束点x座標 
  int yE = 150;  // 収束点y座標
  int[] x = new int[5];  // 描く多角形の頂点のx座標
  int[] y = new int[5];  //                   y座標
  int count = 0;  // カウンタ
  
  public void start() {
    if ( t == null ) {
      t = new Thread(this);
  	  t.start();
  	}
  	else {
  	  t.resume();
  	}
  }
  
  public void run() {
    float u;
  	while (true) {
  	  for (int i=0; i < 5; ++i) {
  	    u = ( (float) count) /9.0f;
  	  	x[i] = (int) ( (1.0f - u)*( (float) xS[i] ) + u*( (float) xE ) );
  	  	y[i] = (int) ( (1.0f - u)*( (float) yS[i] ) + u*( (float) yE ) );
  	  }
  	  repaint();
  	  try { 
  	    Thread.sleep(200);
  	  }
  	  catch(InterruptedException e) {
  	  } 
  	  ++count;
  	  if ( count == 10 ) count = 0;
  	}
  }
  
  public void paint(Graphics g) {
    Color c;
    switch( count ) {
    	case 0: case 1: c = Color.red; break;
    	case 2: case 3: c = Color.yellow; break;
    	case 4: case 5: c = Color.green; break;
    	case 6: case 7: c = Color.cyan; break;
    	default: c = Color.blue;
    }	
    g.setColor(c);
  	g.fillPolygon(x, y, 5);
  }
  
  public void stop() {
      t.suspend();
  }
} 
