/*****************************************************************
** RandomQuilt - generate a random quilt-like pattern of colours
**
** Note: This is an applet.  Execute by loading RandomQuilt.html
** in a browser window, or by entering:
**
**      PROMPT>appletviewer RandomQuilt.html
**
** RandomQuilt.html must contain (at least) the following
**
**   <applet code = "RandomQuilt.class" width = 250 height = 150>
**   </applet>
**
**
** (c) Scott MacKenzie, 2004                             
******************************************************************/
import java.awt.*;
import java.applet.*;

public class RandomQuilt extends Applet
{
   public void paint(Graphics g)
   {
      long t1 = System.currentTimeMillis();
      int temp = 0;
      while (true)
      {
         // updates 10 times per seconds
         int t2 = (int)(System.currentTimeMillis() - t1) / 100;
         if (t2 != temp)
         {
            // generate arguments as random integers
            int x = (int)(Math.random() * 1000) % (XSIZE - 1);
            int y = (int)(Math.random() * 1000) % (YSIZE - 1);
            int width = (int)(Math.random() * 1000) % (XSIZE - 1 - x);
            int height = (int)(Math.random() * 1000) % (YSIZE - 1 - y);
            int red = (int)(Math.random() * 1000) % (256);
            int green = (int)(Math.random() * 1000) % (256);
            int blue = (int)(Math.random() * 1000) % (256);

            // set random color
            g.setColor(new Color(red, green, blue));

            // draw filled rectangle: random position, random proportions
            g.fillRect(x, y, width, height);

            temp = t2;
         }
      }
   }
   static final int XSIZE = 250;
   static final int YSIZE = 150;
}

