/**wmd(number).java by gregvan 
 * RECOMMENDED SIZE: height 500, width 740
 **/

import java.applet.*;
import java.awt.*;

public class wmd23 extends Applet implements Runnable
{
int pepper=7;
int sgt=1;
int eye=2;
int eye3=1;
int a;
int a1=1;
int b;
int b1=-1;
int c;
int c1=2;
int d;
int d1=-2;
int beatle=1;
int abbey=4;
int road=1;
int fool=1;
int moon=3;
int gail=2;
int frank=1;
int zappa=2;
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>8){road=-2;}
if(abbey<-8){road=1;}
zap=zap+zap1;
if(zap>6){zap1=-1;}
if(zap<-6){zap1=2;}
fra=fra+fra1;
if(fra>10){fra1=-1;}
if(fra<-10){fra1=2;}
eye=eye+eye3;
if (eye>12){eye3=-2;}
if (eye<-12){eye3=1;}
pepper=pepper+sgt;
if(pepper>14){sgt=-1;}
if(pepper<-14){sgt=3;}

}
  
frank=frank+1;
if(frank>3){frank=1;}

     rr=rr+rq;
           if(rr>248){rq=-zappa;}
           if(rr<13){rq=zappa;}

             //for loop to paint many images before sleeping .1 second     
       for (int i=0;i<5;i++)
        {

zappa=zappa+1;
if(zappa>5){zappa=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;}
  
       gg=gg+gq;
           if(gg>249){gq=-zappa;}
           if(gg<14){gq=zappa;}
       bb=bb+bq;
           if(bb>250){bq=-zappa;}
           if(bb<15){bq=zappa;}

a=a+a1;
if(a>350){a1=-frank;}
if(a<-350){a1=1;} 

b=b+b1;
if(b>400){b1=-1;}
if(b<-400){b1=frank;} 

c=c+c1;
if(c>375){c1=-1;}
if(c<-375){c1=frank;}

d=d+d1;
if(d>325){d1=-frank;}
if(d<-325){d1=1;}

john=john+gail;
if(john>cx+220){gail=-1;}
if(john<-(cx+220)){gail=zappa;}

paul=paul+dweezel;
if(paul>cx+180){dweezel=-zappa;}
if(paul<-(cx+180)){dweezel=1;}

george=george+moon;
if(george>cx+150){moon=-zappa;}
if(george<-(cx+150)){moon=1;}

ringo=ringo+fool;
if(ringo>cx+160){fool=-1;}
if(ringo<-(cx+160)){fool=zappa;}





//////////////////////////////////////////////////////




//apply the new numbers for lines
        Color tNew = new Color(rr,gg, bb);
        bufferGraphics.setColor(tNew); 


bufferGraphics.drawLine(cx+john+b,cy+paul+a,cx+george+c,cy+ringo+d);
bufferGraphics.drawLine(cx-john-b,cy-paul-a,cx-george-c,cy-ringo-d);
bufferGraphics.drawLine(cx-paul-a,cy+john+b,cx-ringo-d,cy+george+c);
bufferGraphics.drawLine(cx+paul+a,cy-john-b,cx+ringo+d,cy-george-c);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//apply the new numbers for lines
        Color t2New = new Color(rr,gg,256- bb);
        bufferGraphics.setColor(t2New); 


bufferGraphics.drawLine(cx+john+b,cy+paul+a,cx-ringo-d,cy+george+c);
bufferGraphics.drawLine(cx-john-b,cy-paul-a,cx+ringo+d,cy-george-c);
bufferGraphics.drawLine(cx-paul-a,cy+john+b,cx-george-c,cy-ringo-d);
bufferGraphics.drawLine(cx+paul+a,cy-john-b,cx+george+c,cy+ringo+d);

//apply the new numbers for lines
        Color blackNew = new Color(bw,bw,bw);
        bufferGraphics.setColor(blackNew);

john=john-zap+pepper;
ringo=ringo-fra;
george=george+abbey;
paul=paul-eye;


bufferGraphics.drawLine(cx+john+b,cy+paul+a,cx+george+c,cy+ringo+d);
bufferGraphics.drawLine(cx-john-b,cy-paul-a,cx-george-c,cy-ringo-d);
bufferGraphics.drawLine(cx-paul-a,cy+john+b,cx-ringo-d,cy+george+c);
bufferGraphics.drawLine(cx+paul+a,cy-john-b,cx+ringo+d,cy-george-c);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//apply the new numbers for lines
        Color black2New = new Color(256-bw,256-bw,256-bw);
        bufferGraphics.setColor(black2New);
bufferGraphics.drawLine(cx+john+b,cy+paul+a,cx-ringo-d,cy+george+c);
bufferGraphics.drawLine(cx-john-b,cy-paul-a,cx+ringo+d,cy-george-c);
bufferGraphics.drawLine(cx-paul-a,cy+john+b,cx-george-c,cy-ringo-d);
bufferGraphics.drawLine(cx+paul+a,cy-john-b,cx+george+c,cy+ringo+d);

john=john+zap-pepper;
ringo=ringo+fra;
george=george-abbey;
paul=paul+eye;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//apply the new numbers for lines
        Color qwNew = new Color(256-gg,256-bb,256-rr);
        bufferGraphics.setColor(qwNew);

john=john+zap;
ringo=ringo+eye;
george=george-fra+pepper;
paul=paul-abbey;


bufferGraphics.drawLine(cx+john+b,cy+paul+a,cx+george+c,cy+ringo+d);
bufferGraphics.drawLine(cx-john-b,cy-paul-a,cx-george-c,cy-ringo-d);
bufferGraphics.drawLine(cx-paul-a,cy+john+b,cx-ringo-d,cy+george+c);
bufferGraphics.drawLine(cx+paul+a,cy-john-b,cx+ringo+d,cy-george-c);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//apply the new numbers for lines
        Color qw2New = new Color(gg,256-bb,256-rr);
        bufferGraphics.setColor(qw2New);
bufferGraphics.drawLine(cx+john+b,cy+paul+a,cx-ringo-d,cy+george+c);
bufferGraphics.drawLine(cx-john-b,cy-paul-a,cx+ringo+d,cy-george-c);
bufferGraphics.drawLine(cx-paul-a,cy+john+b,cx-george-c,cy-ringo-d);
bufferGraphics.drawLine(cx+paul+a,cy-john-b,cx+george+c,cy+ringo+d);

john=john-zap;
ringo=ringo-eye;
george=george+fra-pepper;
paul=paul+abbey;


 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//apply the new numbers for lines
        Color qNew = new Color(256-rr,bb,gg);
        bufferGraphics.setColor(qNew);

john=john-eye;
ringo=ringo+zap-pepper;
george=george+fra;
paul=paul-abbey;


bufferGraphics.drawLine(cx+john+b,cy+paul+a,cx+george+c,cy+ringo+d);
bufferGraphics.drawLine(cx-john-b,cy-paul-a,cx-george-c,cy-ringo-d);
bufferGraphics.drawLine(cx-paul-a,cy+john+b,cx-ringo-d,cy+george+c);
bufferGraphics.drawLine(cx+paul+a,cy-john-b,cx+ringo+d,cy-george-c);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//apply the new numbers for lines
        Color qwaNew = new Color(256-rr,bb,256-gg);
        bufferGraphics.setColor(qwaNew);
bufferGraphics.drawLine(cx+john+b,cy+paul+a,cx-ringo-d,cy+george+c);
bufferGraphics.drawLine(cx-john-b,cy-paul-a,cx+ringo+d,cy-george-c);
bufferGraphics.drawLine(cx-paul-a,cy+john+b,cx-george-c,cy-ringo-d);
bufferGraphics.drawLine(cx+paul+a,cy-john-b,cx+george+c,cy+ringo+d);

john=john+eye;
ringo=ringo-zap+pepper;
george=george-fra;
paul=paul+abbey;



//apply the new numbers for lines
        Color qxNew = new Color(0,0,0);
        bufferGraphics.setColor(qxNew);

john=john-zap;
ringo=ringo+abbey;
george=george-fra;
paul=paul-eye-pepper;


bufferGraphics.drawLine(cx+john+b,cy+paul+a,cx+george+c,cy+ringo+d);
bufferGraphics.drawLine(cx-john-b,cy-paul-a,cx-george-c,cy-ringo-d);
bufferGraphics.drawLine(cx-paul-a,cy+john+b,cx-ringo-d,cy+george+c);
bufferGraphics.drawLine(cx+paul+a,cy-john-b,cx+ringo+d,cy-george-c);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

bufferGraphics.drawLine(cx+john+b,cy+paul+a,cx-ringo-d,cy+george+c);
bufferGraphics.drawLine(cx-john-b,cy-paul-a,cx+ringo+d,cy-george-c);
bufferGraphics.drawLine(cx-paul-a,cy+john+b,cx-george-c,cy-ringo-d);
bufferGraphics.drawLine(cx+paul+a,cy-john-b,cx+george+c,cy+ringo+d);

john=john+zap;
ringo=ringo-abbey;
george=george+fra;
paul=paul+eye+pepper;






   }//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...

