/**starMaker(number).java by gregvan 
 * RECOMMENDED SIZE: height 560, width 760
 **/

import java.applet.*;
import java.awt.*;

public class starMaker10 extends Applet implements Runnable
{

int qqq=1;
int zappa=1;
int q5=2;
int xx,yy;
int xx2,yy2;
int xxf=1;
int yyf=1;
int q=2;
int qq=1;
int qfac=1;
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 gv;
int wf=1;
int wwf=1;
int w,ww;
int wwq,wq;
int jomamma=6;
int jomamma1=8;
int tf=1;
int ttf=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
	 

//random starting colors
rr=(int)(Math.random() *255);
gg=(int)(Math.random() *255);
bb=(int)(Math.random() *255);
bw=(int)(Math.random() *255);
xx=bw-128;
yy=rr-128;

w=(int)(Math.random() *15);
ww=(int)(Math.random() *13);
jomamma=w;
jomamma1=ww;

               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)
        {


zappa=zappa+1;
if (zappa>100){zappa=1;}

jomamma=jomamma+1;
if (jomamma>14){jomamma=1;}

jomamma1=jomamma1+1;
if (jomamma1>12){jomamma1=1;}

w=w+wf;
if (w>3+jomamma){wf=-1;}
if (w<2){wf=1;}

ww=ww+wwf;
if(ww>3+jomamma1){wwf=-1;}
if(ww<2){wwf=1;}
             //for loop to paint many images before sleeping .1 second     
       for (int i=0;i<3;i++)
        {

 
             //color changer up-down counters
           rr=rr+rq;
           if(rr>253){rq=-w;}
           if(rr<13){rq=1;}
	bw=bw+bwq;
           if(bw>254){bwq=-1;}
           if(bw<2){bwq=1;}
         gg=gg+gq;
           if(gg>250){gq=-ww;}
           if(gg<15){gq=3;}

           bb=bb+bq;
           if(bb>251){bq=-w;}
           if(bb<14){bq=1;}

  wq=wq+tf;
if(wq>w+2){tf=-1;}
if(wq<-w){tf=1;}


wwq=wwq+ttf;
if(wwq>ww+2){ttf=-1;}
if(wwq<-ww){ttf=1;}


xx=xx+(xxf*wq);
if (xx>cx){xxf=-1;}
if (xx<-cx){xxf=1;}
if (xx>cx+50){xx=0;}
if (xx<-(cx+50)){xx=0;}

yy=yy+(yyf*wwq);
if(yy>cx){yyf=-1;}
if(yy<-cx){yyf=1;}
if(yy>cx+50){yy=0;}
if(yy<-(cx+50)){yy=0;}

qfac=qfac+qqq;
if(qfac>zappa){qqq=-1;}
if(qfac<2){qqq=1;}


//apply the new numbers for black squares
        Color zappaNew = new Color(0, 0, 0);
        bufferGraphics.setColor(zappaNew); 


q=qfac;
q5=zappa+2-qfac;

bufferGraphics.fillRect(cx-xx-q,cy-yy-q5,q+q,q5+q5);
bufferGraphics.fillRect(cx+xx-q,cy+yy-q5,q+q,q5+q5);

bufferGraphics.fillRect(cx-xx-q,cy+yy-q5,q+q,q5+q5);
bufferGraphics.fillRect(cx+xx-q,cy-yy-q5,q+q,q5+q5);


bufferGraphics.fillRect(cx-yy-q5,cy-xx-q,q5+q5,q+q);
bufferGraphics.fillRect(cx+yy-q5,cy+xx-q,q5+q5,q+q);

bufferGraphics.fillRect(cx-yy-q5,cy+xx-q,q5+q5,q+q);
bufferGraphics.fillRect(cx+yy-q5,cy-xx-q,q5+q5,q+q);


//apply the new numbers for the stars box 
        Color zstarsNew = new Color(255, 255, 255);
        bufferGraphics.setColor(zstarsNew);

q=1;
q5=1;

xx=xx-100;
yy=yy+100;

bufferGraphics.fillRect(cx-xx-q,cy-yy-q5,q+q,q5+q5);
bufferGraphics.fillRect(cx+xx-q,cy+yy-q5,q+q,q5+q5);

bufferGraphics.fillRect(cx-xx-q,cy+yy-q5,q+q,q5+q5);
bufferGraphics.fillRect(cx+xx-q,cy-yy-q5,q+q,q5+q5);


bufferGraphics.fillRect(cx-yy-q5,cy-xx-q,q5+q5,q+q);
bufferGraphics.fillRect(cx+yy-q5,cy+xx-q,q5+q5,q+q);

bufferGraphics.fillRect(cx-yy-q5,cy+xx-q,q5+q5,q+q);
bufferGraphics.fillRect(cx+yy-q5,cy-xx-q,q5+q5,q+q);


xx=xx+100;
yy=yy-100;

//apply the new numbers for the stars box 
        Color colstarsNew = new Color(bb, rr, gg);
        bufferGraphics.setColor(colstarsNew);

xx=xx+100;
yy=yy-100;

bufferGraphics.fillRect(cx-xx-q,cy-yy-q5,q+q,q5+q5);
bufferGraphics.fillRect(cx+xx-q,cy+yy-q5,q+q,q5+q5);

bufferGraphics.fillRect(cx-xx-q,cy+yy-q5,q+q,q5+q5);
bufferGraphics.fillRect(cx+xx-q,cy-yy-q5,q+q,q5+q5);


bufferGraphics.fillRect(cx-yy-q5,cy-xx-q,q5+q5,q+q);
bufferGraphics.fillRect(cx+yy-q5,cy+xx-q,q5+q5,q+q);

bufferGraphics.fillRect(cx-yy-q5,cy+xx-q,q5+q5,q+q);
bufferGraphics.fillRect(cx+yy-q5,cy-xx-q,q5+q5,q+q);


xx=xx-100;
yy=yy+100;


//apply the new numbers for the stars box 
        Color tinyNew = new Color(255, 255, 255);
        bufferGraphics.setColor(tinyNew);

xx2=xx+xx;
yy2=yy+yy;

if (xx2>cx){xx2=xx2-cx;}
if (yy2>cx){yy2=yy2-cx;}

if (xx2<-cx){xx2=xx2+cx;}
if (yy2<-cx){yy2=yy2+cx;}

bufferGraphics.fillRect(cx-xx,cy-yy2,1,1);
bufferGraphics.fillRect(cx+xx,cy+yy2,1,1);

bufferGraphics.fillRect(cx-xx,cy+yy2,1,1);
bufferGraphics.fillRect(cx+xx,cy-yy2,1,1);


bufferGraphics.fillRect(cx-yy2,cy-xx,1,1);
bufferGraphics.fillRect(cx+yy2,cy+xx,1,1);

bufferGraphics.fillRect(cx-yy2,cy+xx,1,1);
bufferGraphics.fillRect(cx+yy2,cy-xx,1,1);

//apply the new numbers for the stars box 
        Color coltinyNew = new Color(bb, gg, rr);
        bufferGraphics.setColor(coltinyNew);



bufferGraphics.fillRect(cx-xx2,cy-yy,1,1);
bufferGraphics.fillRect(cx+xx2,cy+yy,1,1);

bufferGraphics.fillRect(cx-xx2,cy+yy,1,1);
bufferGraphics.fillRect(cx+xx2,cy-yy,1,1);


bufferGraphics.fillRect(cx-yy,cy-xx2,1,1);
bufferGraphics.fillRect(cx+yy,cy+xx2,1,1);

bufferGraphics.fillRect(cx-yy,cy+xx2,1,1);
bufferGraphics.fillRect(cx+yy,cy-xx2,1,1);





   }//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...

