/* TRAPSCREEN.java - Produces several trapeziums of different
   colors which continuously change dimensions.
   Created by Randel W. McGirr
   blackturtle.us  2011
*/
import java.awt.*; 
import java.applet.*; 
import java.util.*;

public class TRAPSCREEN extends Applet implements Runnable{ 
  Thread bt; //declare the thread 
  Image offI; 
  Dimension d; 
  Random r;
  TRAP[] traps = new TRAP[5];
    
  public void init(){ 
    d = getSize(); 
    offI = createImage(d.width, d.height); 
    traps[0] = new TRAP(d.width, d.height, Color.red);
    traps[1] = new TRAP(d.width, d.height, Color.yellow);
    traps[2] = new TRAP(d.width, d.height, Color.cyan);
    traps[3] = new TRAP(d.width, d.height, Color.magenta);
    traps[4] = new TRAP(d.width, d.height, Color.green);
    bt = new Thread(this); //initiate the thread 
    bt.start(); //start the thread running 
  } 
  
  public void run(){ 
    while(true){
      for(int i=0; i<traps.length; i++){
         traps[i].change();
      }
      try{
        Thread.sleep(100);
      }catch(InterruptedException e){}; 
      repaint();
    }
  } 
  
  public void update(Graphics g){ 
    paint(g); 
  } 
  
  public void paint(Graphics g){ 
    Graphics offG = offI.getGraphics(); 
    offG.setColor(Color.black);
    offG.fillRect(0,0,d.width,d.height);
    for(int i=0; i<traps.length; i++){
      traps[i].draw(offG);
    }
    g.drawImage(offI,0,0,this); 
  } 
}
//<applet code=TRAPSCREEN.class height=400 width=900></applet>
 