/**zipdot(number).java by gregvan 
 * RECOMMENDED SIZE: height 440, width 600
 **/

import java.applet.*;
import java.awt.*;

public class zipdot17 extends Applet implements Runnable
{
int na=8;//size of dots
int nap=16;
 int fred;
int dead;  
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 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() *6);
wq=(int)(Math.random() *25);
wwq=(int)(Math.random() *26);
               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>6){w=1;}
wq=wq+1;
if (wq>22){wq=1;}
wwq=wwq+1;
if(wwq>16){wwq=1;}



		 z=z+zz;
           if(z>231){zz=-w;}
           if(z<-230){zz=w;}
 

y=y+yy;
           if(y>91){yy=-w;}
           if(y<-90){yy=w;}

  


		x=x+xx;
           if(x>240){xx=-w;}
           if(x<-241){xx=w;}

a=a+aa;
           if(a>80){aa=-w;}
           if(a<-81){aa=w;}

             //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;}



	for (int ii=-60;ii<61;ii=ii+10)
          {

  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;}

x=x+ii;
z=z+ii;
 
x=x-y+a;
z=z+a+y;

 if(x>0){
//apply the new numbers for color
        Color cNew = new Color(rr, 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);  
 }       
     //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);




  
x=x+y-a;
z=z-a-y;

x=x-ii;
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...

