/*

*/
import java.awt.*;

public class RecursivePolygons1 extends Frame
{
   public static final int SLEEP_TIME = 200;

   public RecursivePolygons1()
   {
      super( "Drawing Polygons" );
      setSize( 500, 500 );
      show();
   }

   public void recursiveDrawing(int n, Graphics g, int x1, int y1, int x2, int y2)
   {
      if (n == 0) return;

      g.setColor(Color.red);
      int[] xValues1 = {x1, (x1+x2)/2, (x1+x2)/2, x1};
      int[] yValues1 = {y1, y1, (y1+y2)/2, (y1+y2)/2};
      g.fillPolygon( xValues1, yValues1, 4 );
      try{ Thread.sleep(SLEEP_TIME); } catch (InterruptedException e){}

      g.setColor(Color.green);
      int[] xValues2 = {(x1+x2)/2, x2, x2, (x1+x2)/2};
      int[] yValues2 = {y1, y1, (y1+y2)/2, (y1+y2)/2};
      g.fillPolygon( xValues2, yValues2, 4 );
      try{ Thread.sleep(SLEEP_TIME); } catch (InterruptedException e){}

      g.setColor(Color.blue);
      int[] xValues3 = {x1, (x1+x2)/2, (x1+x2)/2, x1};
      int[] yValues3 = {(y1+y2)/2, (y1+y2)/2, y2, y2};
      g.fillPolygon( xValues3, yValues3, 4 );
      try{ Thread.sleep(SLEEP_TIME); } catch (InterruptedException e){}

      recursiveDrawing(n-1, g, (x1+x2)/2, (y1+y2)/2, x2, y2);
   }

   public void paint( Graphics g )
   {
      recursiveDrawing(5, g, 0, 0, 500, 500);
   }


   // The main method creates an instance of this class
   // thereby "running" this program.
   public static void main( String args[] )
   {
      RecursivePolygons1 app = new RecursivePolygons1();
   }//main

}//RecursivePolygons1

