/**island(number).java by gregvan 
code for embedding in webpage....
<applet code="island(number).class" 
height=520 width=760> </applet>
 **/

import java.applet.*;
import java.awt.*;
//~~~~~~make sure this name is exactly the same as filename~~~~~
public class island34 extends Applet implements Runnable
{
int u2;
int u2q=1;
int joe;
int joeq=1;
int mama;
int mamaq=-1;
int a,b,c,q;
int x4,y4;
int x4q=-1;
int y4q=2;
int alice=2;
int ace=2;
int lice=2;
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);
x4=bb-128;
y4=bw-128;


               repaint();
               try
               {Thread.sleep(1000);}
               catch(InterruptedException e) {} 

               while (myRunner != null)
               {
                  repaint(); 
                  try
                  {Thread.sleep(100); }
                  catch (InterruptedException e) {}
               }  
           } 
        }


public void plot4Lines0() {
a=x4-u2;
b=y4+u2;
c=(x4/3)-mama;
q=(y4/3)+joe;

bufferGraphics.drawLine(cx-a,cy-b,cx-c+q,cy-c-q);
bufferGraphics.drawLine(cx+b,cy-a,cx+c+q,cy-c+q);
bufferGraphics.drawLine(cx+a,cy+b,cx+c-q,cy+c+q);
bufferGraphics.drawLine(cx-b,cy+a,cx-c-q,cy+c-q);
}
//~~~end of plot4Lines0~~~~~~~~~~~~~~~

public void plot4Lines1() {
a=x4-u2;
b=y4+u2;
c=(x4/3)-mama;
q=(y4/3)+joe;

bufferGraphics.drawLine(cx+b,cy-a,cx-c+q,cy-c-q);
bufferGraphics.drawLine(cx+a,cy+b,cx+c+q,cy-c+q);
bufferGraphics.drawLine(cx-b,cy+a,cx+c-q,cy+c+q);
bufferGraphics.drawLine(cx-a,cy-b,cx-c-q,cy+c-q);
}
//~~~end of plot4Lines1~~~~~~~~~~~~~~~

       // 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)
        {

alice=alice+1;
if(alice>3){alice=1;}
ace=ace+1;
if(ace>4){ace=1;}
lice=lice+1;
if(lice>5){lice=1;}

joe=joe+joeq;
if(joe>60){joeq=-1;}
if(joe<-60){joeq=1;}
//----------------------------------for loop--------------------------------
//for loop to paint many images before sleeping .1 second     
       for (int i=0;i<2;i++)
        {
mama=mama+mamaq;
if(mama>75){mamaq=-1;}
if(mama<-75){mamaq=1;}
for (int i2=0;i2<2;i2=i2+1)
        {
u2=u2+u2q;
if (u2>90){u2q=-1;}
if (u2<-90){u2q=1;}



for(int i9=0;i9<2;i9++){
//color changer up counters
 rr=rr+rq;
  if(rr>249){rq=-ace;}
  if(rr<6){rq=ace;}
gg=gg+gq;
 if(gg>245){gq=-alice;}
 if(gg<9){gq=alice;}
bb=bb+bq;
  if(bb>243){bq=-lice;}
  if(bb<10){bq=lice;}
bw=bw+bwq;
  if(bw>243){bwq=-1;}
  if(bw<10){bwq=1;}
 Color w0New = new Color(256-rr,256-bw,256-bw);
 Color w1New = new Color(rr, gg, bb);
 Color w2New = new Color(256-rr,256-bb, 256-gg);
 Color w3New = new Color(bw,bw,gg);
 Color w4New = new Color(gg,256-bb, 256-gg);
 Color w5New = new Color(bw,256-bw,gg);



    for (int i3=0;i3<2;i3++)
        {
x4=x4+x4q;
if(x4>120){x4q=-1;}
if(x4<-120){x4q=1;}
y4=y4+y4q;
if(y4>130){y4q=-1;}
if(y4<-130){y4q=1;}


for(int p5=0;p5<5; p5++){
if (p5==0){
cx=150;
cy=100;}
if (p5==1){
cx=610;
cy=100;}
if (p5==2){
cx=380;
cy=260;}
if (p5==3){
cx=150;
cy=420;}
if (p5==4){
cx=610;
cy=420;}
x4=x4+joe;
y4=y4-mama;
 bufferGraphics.setColor(w1New); 
//~~~~~call subroutine~~~~~~~~
plot4Lines0();
 bufferGraphics.setColor(w2New); 
//~~~~~call subroutine~~~~~~~~
plot4Lines1();
x4=x4-joe;
y4=y4+mama;
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&
x4=x4+joe+u2;
y4=y4-mama-u2;

 bufferGraphics.setColor(w0New); 
//~~~~~call subroutine~~~~~~~~
plot4Lines0();
 bufferGraphics.setColor(w3New); 
//~~~~~call subroutine~~~~~~~~
plot4Lines1();

x4=x4-joe-u2;
y4=y4+mama+u2;
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&
x4=x4+joe-u2;
y4=y4-mama+u2;

 bufferGraphics.setColor(w4New); 
//~~~~~call subroutine~~~~~~~~
plot4Lines0();
 bufferGraphics.setColor(w5New); 
//~~~~~call subroutine~~~~~~~~
plot4Lines1();

x4=x4-joe+u2;
y4=y4+mama-u2;
}//end of for p5 loop

}//end of for i3 loop
}//end of for i9 loop
}//end of for i2 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...

