/**a1a(number).java by gregvan 
 * RECOMMENDED SIZE: height 500, width 740
 **/

import java.applet.*;
import java.awt.*;

public class a1a3 extends Applet implements Runnable
{
int a;
int a1=1;
int b;
int b1=1;
int beatle=1;
int abbey=4;
int road=1;
int fool=1;
int moon=3;
int gail=2;
int frank;
int zappa;
int zap=3;
int fra=4;
int zap1=1;
int fra1=1;
int billy;
int fred;
int dweezel=1;
int john;
int paul;
int george;
int ringo;
int martin;
int wings=3;
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);
john=-rr;
george=-gg;
paul=bb;
ringo=bw;


               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)
        {



beatle=beatle+1;
if(beatle>180)
{beatle=1;
abbey=abbey+road;
if(abbey>6){road=-1;}
if(abbey<2){road=1;}
zap=zap+zap1;
if(zap>12){zap1=-1;}
if(zap<2){zap1=1;}
fra=fra+fra1;
if(fra>8){fra1=-1;}
if(fra<2){fra1=1;}
}
  gg=gg+gq;
           if(gg>249){gq=-1;}
           if(gg<8){gq=1;}

             //for loop to paint many images before sleeping .1 second     
       for (int i=0;i<(9-abbey);i++)
        {


a=a+a1;
if(a>300){a1=-2;}
if(a<-300){a1=1;} 

b=b+b1;
if(b>400){b1=-3;}
if(b<-400){b1=1;} 
             //color changer up-down counters
          
if(rr>bb){fred=1;}
else{fred=6;}

	bw=bw+bwq;
           if(bw>248){bwq=-fred;}
           if(bw<8){bwq=fred;}
       

           bb=bb+bq;
           if(bb>251){bq=-2;}
           if(bb<6){bq=1;}


john=john+gail;
if(john>cx+120){gail=-2;}
if(john<-(cx+120)){gail=3;}

paul=paul+dweezel;
if(paul>cx+280){dweezel=-2;}
if(paul<-(cx+280)){dweezel=1;}

george=george+moon;
if(george>cx+150){moon=-1;}
if(george<-(cx+150)){moon=4;}

ringo=ringo+fool;
if(ringo>cx+200){fool=-3;}
if(ringo<-(cx+200)){fool=1;}





//////////////////////////////////////////////////////





zappa=-60;
frank=-90;
 for (int thirdeye=0;thirdeye<abbey;thirdeye=thirdeye+1)
{
rr=rr+rq;
           if(rr>253){rq=-2;}
           if(rr<3){rq=1;}

zappa=zappa+zap;
frank=frank+fra;
//apply the new numbers for lines
        Color greyNew = new Color(rr,gg, bb);
        bufferGraphics.setColor(greyNew); 


john=john+zappa;
paul=paul+frank+frank+frank;
george=george-frank-zappa-zappa;
ringo=ringo+frank;

bufferGraphics.drawLine(cx+john+b,cy+paul+a,cx+george+b,cy+ringo+a);
bufferGraphics.drawLine(cx-john-b,cy+paul+a,cx-george-b,cy+ringo+a);

//apply the new numbers for lines
        Color beatNew = new Color(gg,bb, rr);
        bufferGraphics.setColor(beatNew); 

bufferGraphics.drawLine(cx-john-b,cy-paul+a,cx-george-b,cy-ringo+a);
bufferGraphics.drawLine(cx+john+b,cy-paul+a,cx+george+b,cy-ringo+a);


//apply the new numbers for lines
        Color abeatNew = new Color(256-gg,256-bb, 256-rr);
        bufferGraphics.setColor(abeatNew); 

bufferGraphics.drawLine(cx-john-b,cy-paul+a,cx+george+b,cy+ringo+a);
bufferGraphics.drawLine(cx+john+b,cy-paul+a,cx-george-b,cy+ringo+a);

//apply the new numbers for lines
        Color xxbeatNew = new Color(256-bb,256-rr,256- gg);
        bufferGraphics.setColor(xxbeatNew); 

bufferGraphics.drawLine(cx+john+b,cy+paul+a,cx-george-b,cy-ringo+a);
bufferGraphics.drawLine(cx-john-b,cy+paul+a,cx+george+b,cy-ringo+a);



//apply the new numbers for lines
        Color blackNew = new Color(bw,bw,bw);
        bufferGraphics.setColor(blackNew);

john=john-zap;
ringo=ringo-fra;
george=george+fra;
paul=paul+zap;

bufferGraphics.drawLine(cx+john+b,cy+paul+a,cx+george+b,cy+ringo+a);
bufferGraphics.drawLine(cx-john-b,cy+paul+a,cx-george-b,cy+ringo+a);
bufferGraphics.drawLine(cx-john-b,cy-paul+a,cx+george+b,cy+ringo+a);
bufferGraphics.drawLine(cx+john+b,cy-paul+a,cx-george-b,cy+ringo+a);

//apply the new numbers for lines
        Color xxblackNew = new Color(256-bw,256-bw,256-bw);
        bufferGraphics.setColor(xxblackNew);

bufferGraphics.drawLine(cx-john-b,cy-paul+a,cx-george-b,cy-ringo+a);
bufferGraphics.drawLine(cx+john+b,cy-paul+a,cx+george+b,cy-ringo+a);
bufferGraphics.drawLine(cx+john+b,cy+paul+a,cx-george-b,cy-ringo+a);
bufferGraphics.drawLine(cx-john-b,cy+paul+a,cx+george+b,cy-ringo+a);
john=john+zap;
ringo=ringo+fra;
george=george-fra;
paul=paul-zap;
 
john=john-zappa;
paul=paul-frank-frank-frank;
george=george+frank+zappa+zappa;
ringo=ringo-frank;
}




   }//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...

