/**aaaflower(number).java by gregvan 
 * RECOMMENDED SIZE: height 500, width 740
 **/

import java.applet.*;
import java.awt.*;

public class aaaflower29 extends Applet implements Runnable
{
int bob;
int frank;
int gail=6;
int moon=9;
int gail1=1;
int moon1=1;
int joe;
int blow;
int billy;
int s;
int s2;
int t;
int t2;
int beatle;

int john;
int paul;

int fred;
int zappa=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);
john=-rr;
paul=-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)
        {

joe=joe+1;
if(joe>18){joe=2;}
blow=blow+1;
if(blow>16){blow=2;}
beatle=beatle+1;
if (beatle>200){beatle=-200;}


        //for loop to paint many images before sleeping .1 second     
       for (int i=0;i<2;i++)
        {

zappa=zappa+1;
if(zappa>15){zappa=1;}

billy=billy+1;
if(billy>20){billy=1;} 



             //color changer up-down counters
          
if(rr>bb){fred=1;}
else{fred=16;}

       bw=bw+bwq;
           if(bw>238){bwq=-fred;}
           if(bw<18){bwq=fred;}
      rr=rr+rq;
           if(rr>238){rq=-zappa;}
           if(rr<17){rq=zappa;}

       gg=gg+gq;
           if(gg>239){gq=-zappa;}
           if(gg<16){gq=zappa;}
       bb=bb+bq;
           if(bb>240){bq=-zappa;}
           if(bb<15){bq=zappa;}


	
	gail=gail+gail1;
	if (gail>joe+1){gail1=-1;}
	if (gail<-joe){gail1=1;}

	
	moon=moon+moon1;
	if(moon>blow+1){moon1=-1;}
	if(moon<-blow){moon1=1;}



john=john+gail;
if (john>cx){john=-cx;}
if (john<-cx){john=cx;}
paul=paul+moon;
if (paul>cx){paul=-cx;}
if (paul<-cx){paul=cx;}


//////////////////////////////////////////////////////

s=s+1;
if(s>5){s=1;}
s2=s+s;

t=t+1;
if(t>6){t=1;}
t2=t+t;

//s=2;
//s2=4;




  for (int ii=-4;ii<billy;ii++)
{


zappa=zappa+1;
if(zappa>15){zappa=1;}

       rr=rr+rq;
           if(rr>238){rq=-zappa;}
           if(rr<17){rq=zappa;}
       gg=gg+gq;
           if(gg>239){gq=-zappa;}
           if(gg<16){gq=zappa;}
       bb=bb+bq;
           if(bb>240){bq=-zappa;}
           if(bb<15){bq=zappa;}


//apply the new numbers for boxes
        Color t0New = new Color(rr,gg,bb);
        bufferGraphics.setColor(t0New); 
paul=paul+(ii*ii);
john=john+(ii*3);

bufferGraphics.fillRect(cx+john-s,cy+paul-t,s2,t2);
bufferGraphics.fillRect(cx-john-s,cy-paul-t,s2,t2);
bufferGraphics.fillRect(cx+paul-t,cy-john-s,t2,s2);
bufferGraphics.fillRect(cx-paul-t,cy+john-s,t2,s2);

bufferGraphics.fillRect(cx-john-s,cy+paul-t,s2,t2);
bufferGraphics.fillRect(cx+john-s,cy-paul-t,s2,t2);
bufferGraphics.fillRect(cx-paul-t,cy-john-s,t2,s2);
bufferGraphics.fillRect(cx+paul-t,cy+john-s,t2,s2);

paul=paul-(ii*ii);
john=john-(ii*3);
}


bob=bob+2;
if(bob>cx){bob=-(cx+moon);}
//apply the new numbers for color
        Color t1New = new Color(0,0,0);
        bufferGraphics.setColor(t1New); 
bufferGraphics.drawLine(cx+bob,cy-cx,cx+bob,cy+cx);
bufferGraphics.drawLine(cx-bob,cy-cx,cx-bob,cy+cx);
bufferGraphics.drawLine(0,cy-bob,cx+cx,cy-bob);
bufferGraphics.drawLine(0,cy+bob,cx+cx,cy+bob);
   }//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...

