import java.awt.*;
import java.applet.*;


//sf.gif (saint francis) 200 wide x 200 tall
//lpb60.jpg (luffenpuff beach 760 wide 520 tall

public class sf25 extends Applet implements Runnable
{
int unicorn=0;

int x=0;
int y=0;



int joe=1;
int joeq=1;
int joewah=1;
int joewahq=1;
int mama=1;

int joe2=1;
int joeq2=1;
int joewah2=1;
int joewahq2=1;
int mama2=1;
 private volatile Thread runner;

        private Image Buffer;
        private Graphics gBuffer;
        Image background, snail;
  
      Dimension appletSize;  

        //Init is called first, do any initialisation here
        public void init()
        {
                //create graphics buffer, the size of the applet
        setBackground(Color.black);
   appletSize = this.getSize();     
        Buffer = this.createImage(appletSize.width, appletSize.height);

                gBuffer=Buffer.getGraphics();

                background=getImage(getCodeBase(),"lpb60.jpg");
                snail=getImage(getCodeBase(),"sf.gif");

        }



   



       public void start()
       {
              if (runner == null)
               {
                          runner = new Thread (this);
                         runner.start();
               }
       }




    public void stop() {
        runner = null;
    }

 public void run() {
        Thread thisThread = Thread.currentThread();
        while (runner == thisThread) {
            try {
                thisThread.sleep(35);
            } catch (InterruptedException e){}
           

if(unicorn<2){gBuffer.drawImage(background,0,0,this);}
unicorn=unicorn+1;
if(unicorn>500){unicorn=0;}


                        //move the snail 
mama=mama+1;
if(mama>2){
mama=0;
joewah=joewah+joewahq;
if(joewah>8){joewahq=-1;}
if(joewah<-6){joewahq=1;}
}
joe=joe+joeq;
if(joe>7+joewah){joeq=-1;}
if(joe<-(8+joewah)){joeq=1;}
//-----------------------------
mama2=mama2+1;
if(mama2>3){
mama2=0;
joewah2=joewah2+joewahq2;
if(joewah2>6){joewahq2=-1;}
if(joewah2<-8){joewahq2=1;}
}
joe2=joe2+joeq2;
if(joe2>7+joewah2){joeq2=-1;}
if(joe2<-(5+joewah2)){joeq2=1;}

x=x+3+joe;
y=y+2+joe2;



                        //if it moves past the right border,
                        //let it reappear on the left border
  if(x>appletSize.width){x=-200;}
  if(y>appletSize.height){y=-200;}
  if(x<-200){x=appletSize.width;}
  if(y<-200){y=appletSize.height;}



                        gBuffer.drawImage(snail,x,y,this);
// gBuffer.drawImage(snail,appletSize.width-200-x,appletSize.height-200-y,this);



 
            repaint();
        }
    }


   //is needed to avoid erasing the background by Java
   public void update(Graphics g)
   {
                paint(g);
   }

   public void paint(Graphics g)
   {
                g.drawImage (Buffer,0,0, this);
   }
}