/**a8star(number).java by gregvan 
 * RECOMMENDED SIZE: height 400, width 600
 **/

import java.applet.*;
import java.awt.*;

public class a8star17 extends Applet implements Runnable
{
int qqq=1;
int xx,yy;
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 gvb;
int wf=1;
int wwf=1;
int w,ww;
int wwq,wq;
int jomamma;
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;
yy=rr;

w=(int)(Math.random() *15);
ww=(int)(Math.random() *13);

               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)
        {

jomamma=jomamma+1;
if (jomamma>12){jomamma=0;}
w=w+wf;
if (w>5+jomamma){wf=-1;}
if (w<2){wf=2;}

ww=ww+wwf;
if(ww>4+jomamma){wwf=-1;}
if(ww<2){wwf=1;}
             //for loop to paint many images before sleeping .1 second     
       for (int i=0;i<6;i++)
        {

 
             //color changer up-down counters
           rr=rr+rq;
           if(rr>253){rq=-2;}
           if(rr<3){rq=1;}
	bw=bw+bwq;
           if(bw>254){bwq=-1;}
           if(bw<2){bwq=1;}
         gg=gg+gq;
           if(gg>250){gq=-1;}
           if(gg<5){gq=3;}

           bb=bb+bq;
           if(bb>251){bq=-3;}
           if(bb<4){bq=2;}
  wq=wq+tf;
if(wq>w){tf=-1;}
if(wq<-6){tf=1;}


wwq=wwq+ttf;
if(wwq>6){ttf=-1;}
if(wwq<-ww){ttf=1;}

xx=xx+(xxf*wq);
if (xx>cx){xxf=-1;}
if (xx<-cx){xxf=1;}
if (xx>cx+100){xx=0;}
if (xx<-(cx+100)){xx=0;}

yy=yy+(yyf*wwq);
if(yy>cx){yyf=-1;}
if(yy<-cx){yyf=1;}
if(yy>cx+100){yy=0;}
if(yy<-(cx+100)){yy=0;}

qfac=qfac+qqq;
if(qfac>8){qqq=-1;}
if(qfac<2){qqq=1;}


//stars
//apply the new numbers for stars
        Color wNew = new Color(255, 255, 255);
        bufferGraphics.setColor(wNew); 


q=0;


bufferGraphics.drawLine(cx-yy,cy-xx,cx-yy-q,cy-xx-q);
bufferGraphics.drawLine(cx-xx,cy+yy,cx-xx-q,cy+yy+q);
bufferGraphics.drawLine(cx+yy,cy+xx,cx+yy+q,cy+xx+q);
bufferGraphics.drawLine(cx+xx,cy-yy,cx+xx+q,cy-yy-q);

bufferGraphics.drawLine(cx-yy-xx,cy+yy-xx,cx-yy-xx+q,cy+yy-xx-q);
bufferGraphics.drawLine(cx+yy-xx,cy+yy+xx,cx+yy-xx+q,cy+yy+xx-q);
bufferGraphics.drawLine(cx+yy+xx,cy-yy+xx,cx+yy+xx+q,cy-yy+xx-q);
bufferGraphics.drawLine(cx-yy+xx,cy-yy-xx,cx-yy+xx+q,cy-yy-xx-q);


//stars,colored
//apply the new numbers for stars
        Color xNew = new Color(gg,bb,rr);
        bufferGraphics.setColor(xNew); 
xx=xx+qfac;
yy=yy+qfac;



bufferGraphics.drawLine(cx-yy,cy-xx,cx-yy-q,cy-xx-q);
bufferGraphics.drawLine(cx-xx,cy+yy,cx-xx-q,cy+yy+q);
bufferGraphics.drawLine(cx+yy,cy+xx,cx+yy+q,cy+xx+q);
bufferGraphics.drawLine(cx+xx,cy-yy,cx+xx+q,cy-yy-q);

bufferGraphics.drawLine(cx-yy-xx,cy+yy-xx,cx-yy-xx+q,cy+yy-xx-q);
bufferGraphics.drawLine(cx+yy-xx,cy+yy+xx,cx+yy-xx+q,cy+yy+xx-q);
bufferGraphics.drawLine(cx+yy+xx,cy-yy+xx,cx+yy+xx+q,cy-yy+xx-q);
bufferGraphics.drawLine(cx-yy+xx,cy-yy-xx,cx-yy+xx+q,cy-yy-xx-q);

xx=xx-qfac;
yy=yy-qfac;

//stars,colored
//apply the new numbers for stars
        Color xzNew = new Color(bb,rr,gg);
        bufferGraphics.setColor(xzNew); 
xx=xx-qfac;
yy=yy-qfac;


bufferGraphics.drawLine(cx-yy,cy-xx,cx-yy-q,cy-xx-q);
bufferGraphics.drawLine(cx-xx,cy+yy,cx-xx-q,cy+yy+q);
bufferGraphics.drawLine(cx+yy,cy+xx,cx+yy+q,cy+xx+q);
bufferGraphics.drawLine(cx+xx,cy-yy,cx+xx+q,cy-yy-q);

bufferGraphics.drawLine(cx-yy-xx,cy+yy-xx,cx-yy-xx+q,cy+yy-xx-q);
bufferGraphics.drawLine(cx+yy-xx,cy+yy+xx,cx+yy-xx+q,cy+yy+xx-q);
bufferGraphics.drawLine(cx+yy+xx,cy-yy+xx,cx+yy+xx+q,cy-yy+xx-q);
bufferGraphics.drawLine(cx-yy+xx,cy-yy-xx,cx-yy+xx+q,cy-yy-xx-q);


xx=xx+qfac;
yy=yy+qfac;


//diamond in black

//apply the new numbers for black diamond
        Color zNew = new Color(0, 0, 0);
        bufferGraphics.setColor(zNew); 

gv=gv+1;
if (gv==100)
{

yy=jomamma;
xx=jomamma;

}

if (gv>cx+cx){gv=gv-(cx+cx+cx+jomamma);}

bufferGraphics.drawLine(cx,cy-gv-gv,cx+gv+gv,cy);
bufferGraphics.drawLine(cx,cy+gv+gv,cx-gv-gv,cy);
bufferGraphics.drawLine(cx,cy-gv-gv,cx-gv-gv,cy);
bufferGraphics.drawLine(cx,cy+gv+gv,cx+gv+gv,cy);
if(gv>0)
{
bufferGraphics.drawRect(cx-gv-gv,cy-gv-gv,gv+gv+gv+gv,gv+gv+gv+gv);
}
bufferGraphics.drawLine(cx+gv,cy,cx+gv+gv,cy+cx);
bufferGraphics.drawLine(cx,cy+gv,0,cy+gv+gv);
bufferGraphics.drawLine(cx-gv,cy,cx-gv-gv,cy-cx);
bufferGraphics.drawLine(cx,cy-gv,cx+cx,cy-gv-gv);

gv=-gv;
bufferGraphics.drawLine(cx+gv,cy,cx+gv+gv,cy+cx);
bufferGraphics.drawLine(cx,cy+gv,0,cy+gv+gv);
bufferGraphics.drawLine(cx-gv,cy,cx-gv-gv,cy-cx);
bufferGraphics.drawLine(cx,cy-gv,cx+cx,cy-gv-gv);
gv=-gv;

   }//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...

