/**tds(number).java by gregvan 
code for embedding in webpage....
<applet code="tds(number).class" 
height=520 width=750> </applet>
 **/

import java.applet.*;
import java.awt.*;
//~~~~~~make sure this name is exactly the same as filename~~~~~
public class tds79 extends Applet implements Runnable
{
int alice=2;
int blow;
int blowq=1;
int wind;
int windq=2;

int pal=1;
int palq=1;
int pal2=1;
int pal2q=1;

int x4,y4;
int x5,y5;
int x5q=1;
int y5q=4;

int x4q=3;
int y4q=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 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);
x5=gg-128;
y5=rr-128;

x4=bb-128;
y4=bw-128;


               repaint();
               try
               {Thread.sleep(1000);}
               catch(InterruptedException e) {} 

               while (myRunner != null)
               {
                  repaint(); 
                  try
                  {Thread.sleep(100); }
                  catch (InterruptedException e) {}
               }  
           } 
        }


public void plotDaLines()
        {
bufferGraphics.drawLine(cx-x4,cy-y4,cx-y4,cy+x4);
bufferGraphics.drawLine(cx+x4,cy+y4,cx-y4,cy+x4);
bufferGraphics.drawLine(cx-x4,cy-y4,cx+y4,cy-x4);
bufferGraphics.drawLine(cx+x4,cy+y4,cx+y4,cy-x4);
}
//~~~end of plotDaLines~~~~~~~~~~~~~~~
public void plotDaLines2()
        {
bufferGraphics.drawLine(cx-x5,cy-y5,cx-y5,cy+x5);
bufferGraphics.drawLine(cx+x5,cy+y5,cx-y5,cy+x5);
bufferGraphics.drawLine(cx-x5,cy-y5,cx+y5,cy-x5);
bufferGraphics.drawLine(cx+x5,cy+y5,cx+y5,cy-x5);
}
//~~~end of plotDaLines2~~~~~~~~~~~~~~~
       // 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)
        {

pal=pal+palq;
if(pal>33){palq=-1;}
if(pal<-33){palq=6;}

pal2=pal2+pal2q;
if(pal2>43){pal2q=-4;}
if(pal2<-43){pal2q=1;}

blow=blow+blowq;
if (blow>48){blowq=-1;}
if (blow<-48){blowq=6;}

wind=wind+windq;
if(wind>61){windq=-5;}
if(wind<-61){windq=1;}
//----------------------------------for loop--------------------------------
//for loop to paint many images before sleeping .1 second     
       for (int i=0;i<5;i++)
        {
alice=alice+1;
if(alice>10){alice=1;}
//color changer up counters
 rr=rr+rq;
  if(rr>253){rq=-1;}
  if(rr<2){rq=1;}

gg=gg+gq;
           if(gg>252){gq=-1;}
 if(gg<3){gq=2;}
bb=bb+bq;
           if(bb>251){bq=-3;}
   if(bb<4){bq=1;}
bw=bw+bwq;
           if(bw>242){bwq=-alice;}
 if(bw<12){bwq=alice;}
 Color wNew = new Color(rr, gg, 256-bb);
   Color w2New = new Color(256-rr, gg, bb);
 Color w3New = new Color(256-bb, bw, 256-rr);
   Color w4New = new Color(256-gg, rr, 256-bw);

//color changer up counters



x4=x4+x4q;
if(x4>(cx+150)){x4q=-1;}
if(x4<-(cx+150)){x4q=6;}
y4=y4+y4q;
if(y4>cx+120){y4q=-6;}
if(y4<-(cx+120)){y4q=1;}


x5=x5+x5q;
if(x5>cx){x5q=-1;}
if(x5<-cx){x5q=5;}
y5=y5+y5q;
if(y5>cx+20){y5q=-5;}
if(y5<-(cx+20)){y5q=1;}

        
    for (int i2=-10;i2<10;i2++)
        {
x4=x4-(i2*pal2);
y4=y4+(i2*pal2);
x5=x5+(i2*pal);
y5=y5-(i2*pal);

//apply the new numbers for stars
       
        bufferGraphics.setColor(wNew); 
//~~~~~call subroutine~~~~~~~~
plotDaLines();
//~~~~~~~~~~~~~~~~~~`~
    bufferGraphics.setColor(w3New); 
//~~~~~call subroutine~~~~~~~~
plotDaLines2();
//~~~~~~~~~~~~~~~~~~`~

     
x4=x4+blow;
y4=y4-wind;
x5=x5-blow;
y5=y5+wind;
        bufferGraphics.setColor(w2New); 
//~~~~~call subroutine~~~~~~~~
plotDaLines();

        bufferGraphics.setColor(w4New); 
//~~~~~call subroutine~~~~~~~~
plotDaLines2();
x4=x4-blow;
y4=y4+wind;
x5=x5+blow;
y5=y5-wind;
//~~~~~~~~~~~~~~~~~~`~
x4=x4+(i2*pal2);
y4=y4-(i2*pal2);
x5=x5-(i2*pal);
y5=y5+(i2*pal);
}//end of i2 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...

