/**aaaflower(number).java by gregvan 
 * RECOMMENDED SIZE: height 500, width 740
 **/

import java.applet.*;
import java.awt.*;

public class aaaflowerpower1 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 billy1=1;
int s=3;//size of the filled boxes
int s2;
int ss;//size of the unfilled black boxes
int ss2;
int sst=1;
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;}

s=s+sst;
if (s>7){sst=-1;}
if (s<2){sst=1;}
s2=s+s;
ss=s+1;
ss2=s+s+2;


        //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+billy1;
if(billy>17){billy1=-1;} 
if(billy<2){billy1=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;}



//////////////////////////////////////////////////////






  for (int ii=-billy;ii<billy;ii++)
{

paul=paul+(ii*ii);
john=john+(ii*3);


//apply the new numbers for boxes
        Color t0New = new Color(rr,gg,bb);
        bufferGraphics.setColor(t0New); 
bufferGraphics.fillRect(cx+john-s,cy+paul-s,s2,s2);
bufferGraphics.fillRect(cx-john-s,cy-paul-s,s2,s2);
bufferGraphics.fillRect(cx+paul-s,cy-john-s,s2,s2);
bufferGraphics.fillRect(cx-paul-s,cy+john-s,s2,s2);

bufferGraphics.fillRect(cx-john-s,cy+paul-s,s2,s2);
bufferGraphics.fillRect(cx+john-s,cy-paul-s,s2,s2);
bufferGraphics.fillRect(cx-paul-s,cy-john-s,s2,s2);
bufferGraphics.fillRect(cx+paul-s,cy+john-s,s2,s2);

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//apply the new numbers for boxes
        Color t2New = new Color(0,0,0);
        bufferGraphics.setColor(t2New); 
bufferGraphics.drawRect(cx+john-ss,cy+paul-ss,ss2,ss2);
bufferGraphics.drawRect(cx-john-ss,cy-paul-ss,ss2,ss2);
bufferGraphics.drawRect(cx+paul-ss,cy-john-ss,ss2,ss2);
bufferGraphics.drawRect(cx-paul-ss,cy+john-ss,ss2,ss2);

bufferGraphics.drawRect(cx-john-ss,cy+paul-ss,ss2,ss2);
bufferGraphics.drawRect(cx+john-ss,cy-paul-ss,ss2,ss2);
bufferGraphics.drawRect(cx-paul-ss,cy-john-ss,ss2,ss2);
bufferGraphics.drawRect(cx+paul-ss,cy+john-ss,ss2,ss2);

paul=paul-(ii*ii);
john=john-(ii*3);
}//end of ii loop



   }//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...

