/**boink(number).java by gregvan 
 * RECOMMENDED SIZE: height 520, width 740
 **/

import java.applet.*;
import java.awt.*;

public class boink12 extends Applet implements Runnable{
int boo=1;
int pooh=1;
int chris=1;
int don=1;
int shoe=6;
int shoeq=1;
int earth;
int art=1;
int artq=8;
int fart=1;
int fartq=5;
int fred=1;
int fredq=1;
int womama=1;
int joemama=2;
int blowmama=1;
int billy=1;
int willy=1;
int cat=1;
int dog=1;
int cow=1;
int pig=1;

int john=1;
int george=1;
int paul=1;
int ringo=100;
int martin=1;
int fartin=1;

int i2cube=1;
int i2sq=1;
int king=1;
int kong=1;
int ping=1;
int pong=1;

int god=1;

int dawn=1;
int dawn8=1;
int people=1;

int abba;
int abba1=3;
int jabba;
int jabba1=4;

int abbah;
int jabbah;
int lucysky=3;
int diamonds=2;
int dream=1;
int moody;
int blues=1;
int delta=1;


int rr,gg,bb;//color variables 
int bw=1;
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() *254);
bb=(int)(Math.random() *253);
bw=(int)(Math.random() *252);
cat=rr;
dog=gg;
cow=bb;
pig=bw;
womama=cow+pig;
ringo=bw;
abba=127-gg;
jabba=127-bb;



               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)
        {
//generate a new random direction
earth=earth+1;
if(earth>20){
earth=1;
art=(int)(Math.random() *12);
artq=art-6;
fart=(int)(Math.random() *10);
fartq=fart-6;
}

god=god+1;
if(god>6){god=1;}
boo=boo+1;
if(boo>22){boo=4;}

people=people+1;
if(people>5){
people=1;

dawn=dawn+1;
if(dawn>48){dawn=3;}
dawn8=dawn8+1;
if(dawn8>98){dawn8=3;}
pong=pong+1;
if(pong>5){pong=1;}
ping=ping+1;
if(ping>pong){ping=1;}
}
womama=womama+1;
if(womama>300+dawn+dawn8){womama=-(300+dawn+dawn8);}

joemama=joemama+2;
if(joemama>400-dawn-dawn8){joemama=-(400-dawn-dawn8);}

blowmama=blowmama+3;
if(blowmama>400-dawn-dawn8){blowmama=-(400-dawn-dawn8);}

billy=billy+1;
if(billy>200){billy=-200;}
willy=willy-1;
if(willy<-250){willy=250;}

//for loop to paint many images before sleeping .1 second     
       for (int i=0;i<2;i++)
        {



moody=moody+blues;
if(moody>4+god){blues=-1;}
if(moody<-(5+god)){blues=1;}

dream=dream+delta;
if(dream>5+god){delta=-1;}
if(dream<-(6+god)){delta=1;}


             //color changer up-down counters
       rr=rr+rq;
           if(rr>253){rq=-13;}
           if(rr<3){rq=1;}
       gg=gg+gq;
           if(gg>252){gq=-1;}
           if(gg<4){gq=2;}
       bb=bb+bq;
           if(bb>251){bq=-1;}
           if(bb<5){bq=1;}
       bw=bw+bwq;
           if(bw>250){bwq=-god;}
           if(bw<6){bwq=god;}

if (rr>255){rr=32;}
if (gg>255){gg=255;}
if (bb>255){bb=255;}
if (bw>255){bw=32;}
if (rr<0){rr=224;}
if (gg<0){gg=0;}
if (bb<0){bb=0;}
if (bw<0){bw=224;}
//new ovals in grey*****************************
if(billy>willy){
if (john<paul){
       rr=rr+rq;
           if(rr>245){rq=-8;}
           if(rr<12){rq=8;}
if (rr>255){rr=rr-205;}
if (rr<0){rr=rr+205;}
martin=martin-1;
if(martin<2){martin=cx+100;}
fartin=fartin+2;
if(fartin>cx+100){fartin=1;}
//apply the new numbers for color
        Color martinNew = new Color(rr,rr,rr);
        bufferGraphics.setColor(martinNew); 
bufferGraphics.drawOval(cx-martin,cy-fartin,martin+martin,fartin+fartin);
bufferGraphics.drawOval(cx-fartin,cy-martin,fartin+fartin,martin+martin);
}//end of john<paul

// new july second 2006 ----star in center--------
if(pig>cow){
//apply the new numbers for color
        Color johnNew = new Color(bw,gg,bb);
        bufferGraphics.setColor(johnNew);
}else{
//apply the new numbers for color
        Color john2New = new Color(bb,gg,gg);
        bufferGraphics.setColor(john2New);
}

george=george+1;
if(george>moody+dream+pong+ping){george=-(moody+dream+pong+ping);}

john=john-1;
if (john<2){john=262-dawn8-dawn8;}

bufferGraphics.drawLine(cx+george,cy-john+george,cx-george,cy+john-george);
bufferGraphics.drawLine(cx-john+george,cy+george,cx+john-george,cy-george);
bufferGraphics.drawLine(cx-george,cy-john+george,cx+george,cy+john-george);
bufferGraphics.drawLine(cx-john+george,cy-george,cx+john-george,cy+george);

paul=paul-1;
if(paul<2){paul=194-dawn-dawn;}

bufferGraphics.drawLine(cx-paul-george,cy-paul+george,cx+paul+george,cy+paul-george);
bufferGraphics.drawLine(cx-paul+george,cy+paul+george,cx+paul-george,cy-paul-george);
bufferGraphics.drawLine(cx-paul+george,cy-paul-george,cx+paul-george,cy+paul+george);
bufferGraphics.drawLine(cx-paul-george,cy+paul-george,cx+paul+george,cy-paul+george);

///gnu gnu gnu%%%%%%%% July 1 2006 %%%%%%%%%%%%%%

if(joemama>blowmama){
dog=dog-1;
if (dog<5){dog=cx+100;}
cat=cat+2;
if (cat>cx+100){cat=1;}
cow=cow+1;
if (cow>cx+100){cow=1;}
pig=pig+3;
if (pig>cx+100){pig=1;}
}else{//joemama>blowmama
dog=dog+3;
if (dog>cx+100){dog=1;}
cat=cat+1;
if (cat>cx+100){cat=1;}
cow=cow-2;
if (cow<7){cow=cx+100;}
pig=pig-1;
if (pig<8){pig=cx+100;}
}//end of joemama>blowmama

pooh=pooh+1;
if(pooh>62){pooh=1;}
chris=chris+1;
if(chris>88){chris=1;}
don=don+1;
if(don>77){don=1;}

//apply the new numbers for color
        Color sirdogNew = new Color(bb,rr,gg);
        bufferGraphics.setColor(sirdogNew); 
if(chris>pooh){
bufferGraphics.drawLine(cx,cy-pig,cx+pig,cy);
bufferGraphics.drawLine(cx,cy+pig,cx+pig,cy);
bufferGraphics.drawLine(cx,cy-pig,cx-pig,cy);
bufferGraphics.drawLine(cx,cy+pig,cx-pig,cy);
bufferGraphics.drawRect(cx-pig,cy-pig,pig+pig,pig+pig);
}else{
bufferGraphics.drawOval(cx-dog,cy-dog,dog+dog,dog+dog);
bufferGraphics.drawOval(cx-cat-40,cy-cat-40,cat+cat+80,cat+cat+80);
}
//apply the new numbers for color
        Color sircatNew = new Color(gg,rr,256-bb);
        bufferGraphics.setColor(sircatNew); 
if(chris<pooh){
bufferGraphics.drawLine(cx,cy-dog,cx+dog,cy);
bufferGraphics.drawLine(cx,cy+dog,cx+dog,cy);
bufferGraphics.drawLine(cx,cy-dog,cx-dog,cy);
bufferGraphics.drawLine(cx,cy+dog,cx-dog,cy);
bufferGraphics.drawRect(cx-dog,cy-dog,dog+dog,dog+dog);
}else{
bufferGraphics.drawOval(cx-cat,cy-cat,cat+cat,cat+cat);
bufferGraphics.drawOval(cx-cow-50,cy-cow-50,cow+cow+100,cow+cow+100);
}
//apply the new numbers for color
        Color sircowNew = new Color(256-bb,rr,256-gg);
        bufferGraphics.setColor(sircowNew); 
if(don>pooh){
bufferGraphics.drawLine(cx,cy-cat,cx+cat,cy);
bufferGraphics.drawLine(cx,cy+cat,cx+cat,cy);
bufferGraphics.drawLine(cx,cy-cat,cx-cat,cy);
bufferGraphics.drawLine(cx,cy+cat,cx-cat,cy);
bufferGraphics.drawRect(cx-cat,cy-cat,cat+cat,cat+cat);
}else{
bufferGraphics.drawOval(cx-cow,cy-cow,cow+cow,cow+cow);
bufferGraphics.drawOval(cx-pig-50,cy-pig-50,pig+pig+100,pig+pig+100);
}
//apply the new numbers for color
        Color sirpigNew = new Color(256-gg,256-bb,rr);
        bufferGraphics.setColor(sirpigNew); 
if(don<chris){
bufferGraphics.drawLine(cx,cy-cow,cx+cow,cy);
bufferGraphics.drawLine(cx,cy+cow,cx+cow,cy);
bufferGraphics.drawLine(cx,cy-cow,cx-cow,cy);
bufferGraphics.drawLine(cx,cy+cow,cx-cow,cy);
bufferGraphics.drawRect(cx-cow,cy-cow,cow+cow,cow+cow);
}else{
bufferGraphics.drawOval(cx-pig,cy-pig,pig+pig,pig+pig);
bufferGraphics.drawOval(cx-dog-30,cy-dog-30,dog+dog+60,dog+dog+60);
}
//&&&&&&&&&&&&end of squares and circles&&&&&&&&&&&&&&&
}else{//checking billy>willy

pooh=pooh+1;
if(pooh>62){pooh=1;}
chris=chris+1;
if(chris>88){chris=1;}
don=don+1;
if(don>77){don=1;}

//8 circles on sides===========================
if(pooh>chris){
ringo=ringo+1;
if(ringo>cx){ringo=-cx;}
}else{
ringo=ringo-1;
if(ringo<-cx){ringo=cx;}
}
//new july second circles away from center========
if(blowmama>womama){
fred=fred+fredq;
if(fred>cx+80){fredq=-2;}
if(fred<10){fredq=1;}
//apply the new numbers for color
        Color fredNew = new Color(rr,rr,bb);
        bufferGraphics.setColor(fredNew);
bufferGraphics.drawOval(cx-ringo-fred,cy-ringo-fred,fred+fred,fred+fred);
bufferGraphics.drawOval(cx-ringo-fred,cy+ringo-fred,fred+fred,fred+fred);
bufferGraphics.drawOval(cx+ringo-fred,cy-ringo-fred,fred+fred,fred+fred);
bufferGraphics.drawOval(cx+ringo-fred,cy+ringo-fred,fred+fred,fred+fred);
}else{
fred=fred+fredq;
if(fred>cx+80){fredq=-1;}
if(fred<10){fredq=2;}
//apply the new numbers for color
        Color fredbwNew = new Color(gg,gg,rr);
        bufferGraphics.setColor(fredbwNew);
bufferGraphics.drawOval(cx-ringo-fred,cy-fred,fred+fred,fred+fred);
bufferGraphics.drawOval(cx-fred,cy+ringo-fred,fred+fred,fred+fred);
bufferGraphics.drawOval(cx+ringo-fred,cy-fred,fred+fred,fred+fred);
bufferGraphics.drawOval(cx-fred,cy-ringo-fred,fred+fred,fred+fred);
}//end of don>pooh

lucysky=lucysky+abba1;
if(lucysky>15-moody){abba1=-1;}
if(lucysky<-(6+dream)){abba1=1;}

diamonds=diamonds+jabba1;
if (diamonds>18-dream){jabba1=-1;}
if (diamonds<-(7+moody)){jabba1=1;}

if(pig>cat){
abba=abba+artq;
}else{
abba=abba-lucysky;
}
if (abba>cx+20){abba=-200;}
if (abba<-(cx+20)){abba=200;}

if(dog>cow){
jabba=jabba+fartq;
}else{
jabba=jabba-diamonds;
}
if (jabba>cx+20){jabba=-200;}
if (jabba<-(cx+20)){jabba=200;}


//@@@@@@@@@@new july 1 2006@@@@@@@@@@@@@@@@@@@

if(fartin<martin){
shoe=shoe+shoeq;
if(shoe>boo){shoeq=-1;}
if(shoe<3){shoeq=1;}
}
king=shoe;
kong=shoe+shoe;



if(dog>cat){
rr=rr+shoe;
if(rr>255){rr=rr-255;}
//apply the new numbers for color
        Color topwNew = new Color(256-gg,bb,256-rr);
        bufferGraphics.setColor(topwNew); 
}else{
bw=bw+bwq;
if(bw>240){bwq=-god;}
if(bw<16){bwq=god;}
//apply the new numbers for color
        Color topcolNew = new Color(bw,bw,bw);
        bufferGraphics.setColor(topcolNew); 
}//end of dog>cat

bufferGraphics.fillOval(cx+abba-king,cy+jabba-king,kong,kong);
bufferGraphics.fillOval(cx-abba-king,cy-jabba-king,kong,kong);

bufferGraphics.fillOval(cx+jabba-king,cy-abba-king,kong,kong);
bufferGraphics.fillOval(cx-jabba-king,cy+abba-king,kong,kong);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bufferGraphics.fillOval(cx+abba+jabba-king,cy-abba+jabba-king,kong,kong);
bufferGraphics.fillOval(cx-abba+jabba-king,cy-abba-jabba-king,kong,kong);

bufferGraphics.fillOval(cx-abba-jabba-king,cy+abba-jabba-king,kong,kong);
bufferGraphics.fillOval(cx+abba-jabba-king,cy+abba+jabba-king,kong,kong);
//#############basketball jones#################################

abba=-abba;
bufferGraphics.fillOval(cx+abba-king,cy+jabba-king,kong,kong);
bufferGraphics.fillOval(cx-abba-king,cy-jabba-king,kong,kong);

bufferGraphics.fillOval(cx+jabba-king,cy-abba-king,kong,kong);
bufferGraphics.fillOval(cx-jabba-king,cy+abba-king,kong,kong);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bufferGraphics.fillOval(cx+abba+jabba-king,cy-abba+jabba-king,kong,kong);
bufferGraphics.fillOval(cx-abba+jabba-king,cy-abba-jabba-king,kong,kong);

bufferGraphics.fillOval(cx-abba-jabba-king,cy+abba-jabba-king,kong,kong);
bufferGraphics.fillOval(cx+abba-jabba-king,cy+abba+jabba-king,kong,kong);
abba=-abba;

//~~~~~~~~~~~~~~~~~ovals in color~~~~~~~~~~~~~~~~~~~~~~~
if (chris<pooh){
       rr=rr+rq;
           if(rr>245){rq=-8;}
           if(rr<12){rq=8;}
if (rr>255){rr=rr-205;}
if (rr<0){rr=rr+205;}
martin=martin-1;
if(martin<2){martin=cx+100;}
fartin=fartin+2;
if(fartin>cx+100){fartin=1;}
//apply the new numbers for color
        Color martin8New = new Color(rr,gg,256-rr);
        bufferGraphics.setColor(martin8New); 
bufferGraphics.drawOval(cx-martin,cy-fartin,martin+martin,fartin+fartin);
bufferGraphics.drawOval(cx-fartin,cy-martin,fartin+fartin,martin+martin);
}//end of chris<pooh

}//end of billy>willy

   }//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...

