/**adWord(number).java by gregvan
 * RECOMMENDED SIZE: height 80, width 600
* you may change the words by modifying
* the html on your webpage... parameters
* pass what you want to say to the applet
*<applet code=artword(number).class
*height=80 width=600>
*<param name="sw" value="Stationary Words...">
*</applet>
**/


import java.applet.*;
import java.awt.*;

public class adword11 extends Applet implements Runnable
{
   
int rr,gg,bb;//color variables  
int r1=1; //color up-down counters
int g1=1;  
int b1=1;   
int x, y; //locations
int z;
int a;
int cx; // applet.width/4
int cy; // applet.height/4
int cx2;
int zz=1; //initial value of up-down counters
int xx=1;
int yy=1;
int aa=1;
String yourWords;
String yourWords1;
String moreWords;
String stationaryWords;        
        Thread    myRunner;


        Image     buffer;         
        Dimension appletSize;     
        Graphics  bufferGraphics;
        
        public void init()
        {
// get the words from the webpages html                


stationaryWords=getParameter("sw");
if (stationaryWords==null){stationaryWords="";} 
            
      setBackground(Color.black);
               
      appletSize = this.getSize();

      buffer = this.createImage(appletSize.width, appletSize.height);
      cx=appletSize.width/4;
      cy=appletSize.height/4;
  cx2=appletSize.width/2;
      bufferGraphics = buffer.getGraphics();
        }

        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
	x=(int)(Math.random() *256);
	y=(int)(Math.random() *256);
	z=(int)(Math.random() *256);
	a=(int)(Math.random() *100);   
        rr=x;//random color 
        gg=y;
        bb=z;  

                        repaint();
                        try
                        {
              // sleep for 1 second (1000 msec = 1 sec)
                                Thread.sleep(100);
                        }
                        catch(InterruptedException e) 
                        {
                        } 

                        while (myRunner != null)
                        {
                               
                                repaint(); 
                                try
                                {
                     // pause for .1 second
                               Thread.sleep(100);  
                                }
                                catch (InterruptedException e) 
                                {
                                }
                        }  
                }  //end while thread executing
        }

        //suspends execution when user leaves page
        public void stop()
        { 
                if (myRunner != null)
                {
                        myRunner = null;
                }
        }

        public void update(Graphics g)
        {
                paint(g);
        }


        public void paint(Graphics g)
        {
        for(int i=0; i<5;i++)
         {
//color changer 
        rr=rr+r1;
        if(rr>250){r1=-3;}
        if(rr<5){r1=3;}
        gg=gg+g1;
        if(gg>251){g1=-1;}
        if(gg<4){g1=1;}
        bb=bb+b1;
        if(bb>249){b1=-2;}
        if(bb<6){b1=2;}
//move the location of the words
//classic up-down counters
//we use x,z,y and a to define where to start the lines


        z=z+zz;
        if(z>(cx2+50)){zz=-1;}
        if(z<-(cx2-50)){zz=1;}
        a=a+aa;
        if(a>cy+10){aa=-1;}
        if(a<-(cy+10)){aa=1;}
        x=x+xx;
        if(x>cx2+30){xx=-2;}
        if(x<-(cx2+30)){xx=1;}
        y=y+yy;
        if(y>cy+80){yy=-2;}  
        if(y<-(cy+80)){yy=1;} 


Color eNew = new Color(rr, gg, bb);
   bufferGraphics.setColor(eNew);
   bufferGraphics.setFont(new Font("Serif",Font.PLAIN,70));

//use the parameters sent from the webpage

bufferGraphics.drawString(""+stationaryWords ,15,65); 
Color gNew = new Color(gg,256-bb, 256-rr);
   bufferGraphics.setColor(gNew);
bufferGraphics.drawLine(cx2-z+x+a,-cy-y,cx2-z+x-a,80+cy+y);
bufferGraphics.drawLine(cx2+z-x-a,80+cy+y,cx2+z-x+a,-cy-y);

}//end of for loop
// [1]"then copy the off-screen buffer onto the screen"
              
        g.drawImage(buffer, 0, 0, this);
        }
}//end of program

