/**a1spiral(number).java by gregvan 
 * RECOMMENDED SIZE: height 500, width 740
 **/

import java.applet.*;
import java.awt.*;

public class a1spiral11 extends Applet implements Runnable
{
int eye=2;
int eye3=1;
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=5;
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>7){zap1=-1;}
if(zap<2){zap1=1;}
fra=fra+fra1;
if(fra>8){fra1=-1;}
if(fra<2){fra1=1;}
eye=eye+eye3;
if (eye>9){eye3=-1;}
if (eye<2){eye3=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<4;i++)
        {

a=a+a1;
if(a>250){a1=-1;}
if(a<-250){a1=1;} 

b=b+b1;
if(b>300){b1=-1;}
if(b<-300){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+20){gail=-2;}
if(john<-(cx+20)){gail=1;}

paul=paul+dweezel;
if(paul>cx+80){dweezel=-2;}
if(paul<-(cx+80)){dweezel=1;}

george=george+moon;
if(george>cx+50){moon=-1;}
if(george<-(cx+50)){moon=2;}

ringo=ringo+fool;
if(ringo>cx+60){fool=-1;}
if(ringo<-(cx+60)){fool=2;}





//////////////////////////////////////////////////////





zappa=-20;
frank=-30;
 for (int thirdeye=1;thirdeye<3;thirdeye=thirdeye+1)
{
rr=rr+rq;
           if(rr>253){rq=-2;}
           if(rr<3){rq=1;}

zappa=zappa+zap;
frank=frank+fra;


john=john+zappa;
paul=paul+frank;
george=george-zappa;
ringo=ringo-frank;

//apply the new numbers for lines
        Color greyNew = new Color(rr,gg, bb);
        bufferGraphics.setColor(greyNew); 


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+john+b,cy+paul+a);
bufferGraphics.drawLine(cx+george-b,cy+ringo-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-john-b,cy-paul-a);
bufferGraphics.drawLine(cx-george+b,cy-ringo+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+abbey;
paul=paul-eye;

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+john+b,cy+paul+a);
bufferGraphics.drawLine(cx+george-b,cy+ringo-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-john-b,cy-paul-a);
bufferGraphics.drawLine(cx-george+b,cy-ringo+a,cx-george-b,cy-ringo-a);
john=john+zap;
ringo=ringo+fra;
george=george-abbey;
paul=paul+eye;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//apply the new numbers for lines
        Color qblackNew = new Color(256-gg,256-bb,256-rr);
        bufferGraphics.setColor(qblackNew);

john=john+eye;
ringo=ringo+zap;
george=george-fra;
paul=paul-abbey;

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+john+b,cy+paul+a);
bufferGraphics.drawLine(cx+george-b,cy+ringo-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-john-b,cy-paul-a);
bufferGraphics.drawLine(cx-george+b,cy-ringo+a,cx-george-b,cy-ringo-a);
john=john-eye;
ringo=ringo-zap;
george=george+fra;
paul=paul+abbey;


 
john=john-zappa;
paul=paul-frank;
george=george+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...

