/**artx(number).java by gregvan 
 * RECOMMENDED SIZE: height 600, width 600
 **/

import java.applet.*;
import java.awt.*;

public class artx0 extends Applet implements Runnable
{
int na=8;//size of dots/squares
int nap=16;
int ma=8;//size of dots
int map=16;
 int fred;//size of squares
int dead=1; 
int ha; 
int rr,gg,bb;//color variables 
int bw;//black and white 
int bwq=1;      
int rq=1; // color up-down factors
int gq=1;
int bq=1;

int w,ww;
int wwq,wq;
int x, y; //endpoint locations
int z;
int a;
int a1;
int z1;
int zz=1; //endpoint up-down counters
int xx=2;
int yy=3;
int aa=4;
int cx; //center of screen x
int cy; //center of screen y

        Thread    myRunner;
        Image     buffer;         
        Dimension appletSize;     
        Graphics  bufferGraphics; 

        public void init()
        {    
        setBackground(Color.black);
        appletSize = this.getSize();     
        buffer = this.createImage(appletSize.width, appletSize.height);
        bufferGraphics = buffer.getGraphics();
	cx=appletSize.width/2;
        cy=appletSize.height/2;

        }

        public void start()
        {
             if (myRunner == null)
             {
                 myRunner = new Thread(this);
                 myRunner.start();
             }
        }

        public void run()
        {
            Thread  executingThread;                   
            executingThread = Thread.currentThread();

            while (myRunner == executingThread)
            {
               //new random numbers to start animation
	       x=(int)(Math.random() *400);
		x=x-200;

               z=(int)(Math.random() *500);
		z=z-250;

//random starting colors
rr=(int)(Math.random() *255);
gg=(int)(Math.random() *255);
bb=(int)(Math.random() *255);
bw=(int)(Math.random() *255);
w=(int)(Math.random() *5);
wq=(int)(Math.random() *22);
wwq=(int)(Math.random() *20);
               repaint();
               try
               {Thread.sleep(1000);}
               catch(InterruptedException e) {} 

               while (myRunner != null)
               {
                  repaint(); 
                  try
                  {Thread.sleep(100); }
                  catch (InterruptedException e) {}
               }  
           } 
        }

       // make sure the animation really stops when exiting webpage
        public void stop()
        { 
          if (myRunner != null)
             { myRunner = null; }
        }

        //used to prevent blinking graphics....
        public void update(Graphics g)
        {paint(g);}

        public void paint(Graphics g)
        {

fred=fred+dead;
if (fred>8){dead=-1;}
if (fred<2){dead=1;}
ma=ma+1;
if(ma>11){ma=1;}
  
             //for loop to paint many images before sleeping .1 second     
        for (int i=0;i<2;i++)
          {


w=w+1;
if (w>5){w=1;}
wq=wq+1;
if (wq>22){wq=1;}
wwq=wwq+1;
if(wwq>20){wwq=1;}



		 z=z+zz;
           if(z>231){zz=-w;}
           if(z<-230){zz=w;}
 

y=y+yy;
           if(y>191){yy=-w;}
           if(y<-190){yy=w;}

  


		x=x+xx;
           if(x>240){xx=-w;}
           if(x<-241){xx=w;}

a=a+aa;
           if(a>180){aa=-w;}
           if(a<-181){aa=w;}
a1=a1+1;
if (a1>220){a1=-220;}
z1=z1+2;
if(z1>200){z1=-200;}
             //color changer up-down counters
           rr=rr+rq;
           if(rr>231){rq=-wq;}
           if(rr<23){rq=wwq;}
	bw=bw+bwq;
           if(bw>224){bwq=-wwq;}
           if(bw<29){bwq=wq;}
         gg=gg+gq;
           if(gg>227){gq=-wwq;}
           if(gg<27){gq=wq;}

           bb=bb+bq;
           if(bb>229){bq=-wq;}
           if(bb<25){bq=wwq;}
if (a>0){
//apply the new numbers for color
        Color qNew = new Color(bw, bb, rr);
        bufferGraphics.setColor(qNew);     
//draw lanes set1
bufferGraphics.drawLine(cx+x,cy+y,cx+z1,cy+a1);
bufferGraphics.drawLine(cx-x,cy-y,cx-z1,cy-a1);
//draw lanes set2
bufferGraphics.drawLine(cx+x,cy-y,cx+z1,cy-a1);
bufferGraphics.drawLine(cx-x,cy+y,cx-z1,cy+a1);
//draw lanes set3
bufferGraphics.drawLine(cx+y,cy+x,cx+a1,cy+z1);
bufferGraphics.drawLine(cx-y,cy-x,cx-a1,cy-z1);
//draw lanes set4
bufferGraphics.drawLine(cx+y,cy-x,cx+a1,cy-z1);
bufferGraphics.drawLine(cx-y,cy+x,cx-a1,cy+z1); 
}
if (x>0){
//apply the new numbers for color
        Color gNew = new Color(256-bw, rr, rr);
        bufferGraphics.setColor(gNew); 
z=z+80;
a=a-50;    
//draw lanes set1
bufferGraphics.drawLine(cx+x,cy+y,cx+z1,cy+a1);
bufferGraphics.drawLine(cx-x,cy-y,cx-z1,cy-a1);
//draw lanes set2
bufferGraphics.drawLine(cx+x,cy-y,cx+z1,cy-a1);
bufferGraphics.drawLine(cx-x,cy+y,cx-z1,cy+a1);
//draw lanes set3
bufferGraphics.drawLine(cx+y,cy+x,cx+a1,cy+z1);
bufferGraphics.drawLine(cx-y,cy-x,cx-a1,cy-z1);
//draw lanes set4
bufferGraphics.drawLine(cx+y,cy-x,cx+a1,cy-z1);
bufferGraphics.drawLine(cx-y,cy+x,cx-a1,cy+z1);  
z=z-80;
a=a+50; 
}
	for (int ii=-50;ii<51;ii=ii+10)
          {

 
bw=bw+bwq;
           if(bw>224){bwq=-wwq;}
           if(bw<29){bwq=wq;}

if (a>0){x=x+ii;}
if (y>0){z=z+ii;}
 
x=x-y;
z=z+a;

 if(x>0){
//apply the new numbers for color
        Color cNew = new Color(bw, gg, bb);
        bufferGraphics.setColor(cNew);  
 }
  if(x<1){
//apply the new numbers for black and white
        Color ccNew = new Color(bw, bw, bw);
        bufferGraphics.setColor(ccNew);  
 } 
if (z>0){ 
na=ma;
nap=na+na;     
     //draw the dots set 1
        bufferGraphics.fillOval(cx- x-na,cy- z-na,nap,nap);
      bufferGraphics.fillOval(cx+ x-na,cy+ z-na,nap,nap);
 //draw the dots set 2
        bufferGraphics.fillOval(cx+ z-na,cy- x-na,nap,nap);
      bufferGraphics.fillOval(cx- z-na,cy+ x-na,nap,nap);
 //draw the dots set 3
        bufferGraphics.fillOval(cx- x-na,cy+ z-na,nap,nap);
      bufferGraphics.fillOval(cx+ x-na,cy- z-na,nap,nap);
 //draw the dots set 4
        bufferGraphics.fillOval(cx+ z-na,cy+ x-na,nap,nap);
      bufferGraphics.fillOval(cx- z-na,cy- x-na,nap,nap);
}

if (a>0){
//apply the new numbers for colors
        Color tbNew = new Color(gg,bb, rr);
        bufferGraphics.setColor(tbNew);  
}
if (a<1){
gg=gg+gq;
           if(gg>227){gq=-wwq;}
           if(gg<27){gq=wq;}
//apply the new numbers for black and white
        Color txNew = new Color(gg,gg, gg);
        bufferGraphics.setColor(txNew);  
}
if(y<0){

x=x+60;
z=z+90;
na=fred;
nap=na+na;
 //draw the Rect set 1
        bufferGraphics.fillRect(cx- x-na,cy- z-na,nap,nap);
      bufferGraphics.fillRect(cx+ x-na,cy+ z-na,nap,nap);
 //draw the Rect set 2
        bufferGraphics.fillRect(cx+ z-na,cy- x-na,nap,nap);
      bufferGraphics.fillRect(cx- z-na,cy+ x-na,nap,nap);
 //draw the Rect set 3
        bufferGraphics.fillRect(cx- x-na,cy+ z-na,nap,nap);
      bufferGraphics.fillRect(cx+ x-na,cy- z-na,nap,nap);
 //draw the Rect set 4
        bufferGraphics.fillRect(cx+ z-na,cy+ x-na,nap,nap);
      bufferGraphics.fillRect(cx- z-na,cy- x-na,nap,nap);
x=x-60;
z=z-90;
}











x=x+y;
z=z-a;

if(a>0){x=x-ii;}

if(y>0){z=z-ii;}
}
       
    }//end of for loop i
     // move the entire buffer onto the display screen and change
     // pixels that are a different color...
      g.drawImage(buffer, 0, 0, this);
    }
} // end of the program...

