/**qart(number).java by gregvan 
 * RECOMMENDED SIZE: height 600, width 600
 **/

import java.applet.*;
import java.awt.*;

public class qart7 extends Applet implements Runnable
{

int billy=15;//distance between lines
int silly=60;
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 a1,x1;
int z1,y1;
int x2=1;
int y2=1;
int z2=1;
int a2=1;

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
	       x1=(int)(Math.random() *400);
		x1=x1-200;

               z1=(int)(Math.random() *500);
		z1=z1-250;

//random starting colors
rr=(int)(Math.random() *255);
gg=(int)(Math.random() *255);
bb=(int)(Math.random() *255);
bw=(int)(Math.random() *255);
a1=rr;//random endpoints
y1=bb;
w=(int)(Math.random() *4);
wq=(int)(Math.random() *14);
wwq=(int)(Math.random() *15);
               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)
        {




  
             //for loop to paint many images before sleeping .1 second     
       for (int i=0;i<2;i++)
        {


w=w+1;
if (w>4){w=1;}
wq=wq+1;
if (wq>14){wq=1;}
wwq=wwq+1;
if(wwq>15){wwq=1;}






             //color changer up-down counters
           rr=rr+rq;
           if(rr>240){rq=-wq;}
           if(rr<16){rq=wwq;}
	bw=bw+bwq;
           if(bw>239){bwq=-wwq;}
           if(bw<17){bwq=wq;}
         gg=gg+gq;
           if(gg>238){gq=-wwq;}
           if(gg<18){gq=wq;}

           bb=bb+bq;
           if(bb>237){bq=-wq;}
           if(bb<19){bq=wwq;}


//move endpoints by w
x1=x1+x2;
if(x1>280){x2=-1;}
if(x1<-280){x2=w;}

y1=y1+y2;
if(y1>320){y2=-w;}
if(y1<-320){y2=1;}

a1=a1+a2;
if (a1>360){a2=-1;}
if (a1<-360){a2=w;}
z1=z1+z2;
if(z1>300){z2=-w;}
if(z1<-300){z2=1;}


 for (int iii=-silly;iii<=silly;iii=iii+billy)
          {
if(z1>0){//speed up color change rate
bw=bw+bwq;
           if(bw>244){bwq=-2;}
           if(bw<12){bwq=3;}
}
//apply the new numbers for greyscale
        Color qNew = new Color(bw, bw, bw);
        bufferGraphics.setColor(qNew);  
x1=x1-iii-iii;
y1=y1+iii+iii;  
a1=a1-iii;
z1=z1-iii;
//draw lanes set1
bufferGraphics.drawLine(cx+x1,cy+y1,cx+z1,cy+a1);
bufferGraphics.drawLine(cx-x1,cy-y1,cx-z1,cy-a1);
//draw lanes set3
bufferGraphics.drawLine(cx+y1,cy-x1,cx+a1,cy-z1);
bufferGraphics.drawLine(cx-y1,cy+x1,cx-a1,cy+z1);


if(a1>0){//speed up color change rate
 rr=rr+rq;
           if(rr>245){rq=-1;}
           if(rr<11){rq=1;} 
}
//apply the new numbers for color
        Color gNew = new Color(bb, rr, gg);
        bufferGraphics.setColor(gNew); 
a1=a1-5;
z1=z1-5;

//draw lanes set1
bufferGraphics.drawLine(cx+x1,cy+y1,cx+z1,cy+a1);
bufferGraphics.drawLine(cx-x1,cy-y1,cx-z1,cy-a1);
//draw lanes set3
bufferGraphics.drawLine(cx+y1,cy-x1,cx+a1,cy-z1);
bufferGraphics.drawLine(cx-y1,cy+x1,cx-a1,cy+z1);

a1=a1+iii+5;
z1=z1+iii+5;
x1=x1+iii+iii;
y1=y1-iii-iii;  
}// end of for iii loop

	
       
   }//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...

