/**colorword(number).java by gregvan
 * RECOMMENDED SIZE: height 500, width 750
* you may change the words by modifying
* the html on your webpage... parameters
* pass what you want to say to the applet
*<applet code=colorword(number).class
*height=400 width=750>
*<param name="yw" value="your words go here...">
*<param name="yw1" value="your words second line...">
*<param name="mw" value="more words">
*<param name="sw" value="Stationary Words...">
*</applet>
**/


import java.applet.*;
import java.awt.*;

public class colorword7 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 b;
int c;
int cx; // appletSize.width/4
int cy; // appletSize.height/4
int size=10;//word size
int size1=1;
int size2=10;
int size3=1;
int cx2;//half appletSize.width
int cy2;
int zz=1; //initial value of up-down counters
int xx=1;
int yy=1;
int aa=1;
int bx=1;
int cc=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                

yourWords=getParameter("yw");
if (yourWords==null){yourWords="";}
yourWords1=getParameter("yw1");
if (yourWords1==null){yourWords1="";}
moreWords=getParameter("mw");
if (moreWords==null){moreWords="";}
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;
      cy2=appletSize.height/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() *300);
		y=(int)(Math.random() *100);
		z=(int)(Math.random() *300);
		a=(int)(Math.random() *100);     

                        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<3;i++)
         {
//color changer 
        rr=rr+7;
        if(rr>255){rr=rr-255;}
      
        gg=gg+3;
        if(gg>255){gg=gg-255;}
      
        bb=bb+2;
        if(bb>255){bb=bb-255;}
      
//move the location of the words
//classic up-down counters
//we use x and z to define where to start the words
//sometimes, zz=-1 and xx=1
//then the words stop moving...
//y and a are used for vertical position...

        z=z+zz;
        if(z>cx2){zz=-2;}
        if(z<-20){zz=1;}
        a=a+aa;
        if(a>cy2){aa=-1;}
        if(a<-15){aa=2;}
        x=x+xx;
        if(x>cx2){xx=-2;}
        if(x<-25){xx=1;}
        y=y+yy;
        if(y>cy2){yy=-1;}  
        if(y<-10){yy=2;}
        b=b+bx;
        if(b>cy){bx=-1;}
        if(b<-30){bx=2;}
        c=c+cc;
        if(c>cx){cc=-2;}
        if(c<-35){cc=1;}
 
//change the letter size
size=size+size1;
if(size>50){size1=-1;}
if(size<10){size1=2;}
size2=size2+size3;
if(size2>60){size3=-2;}
if(size2<10){size3=1;}


Color eNew = new Color(rr, gg, bb);
   bufferGraphics.setColor(eNew);
   bufferGraphics.setFont(new Font("Serif",Font.PLAIN,size+size2));

//use the parameters sent from the webpage
// the moving words
  bufferGraphics.drawString(""+yourWords ,cx-x+z-c+a-y,cy+y+a-b-z);
 bufferGraphics.drawString(""+yourWords1 ,cx-x+z-c+a-y+20,cy+y+a-b-z+65);
Color fNew = new Color(bb,256- gg,rr);
   bufferGraphics.setColor(fNew);
   bufferGraphics.setFont(new Font("Serif",Font.PLAIN,(120-(size+size2))));
  bufferGraphics.drawString(""+moreWords ,cx+x-z+b+a-y,cy+cy-y-a+c+x+z); 

//this color is different from the moving words
//because i switched the rr and gg
Color dNew = new Color(gg, rr, bb);
bufferGraphics.setColor(dNew);
 bufferGraphics.setFont(new Font("Serif",Font.PLAIN,80));
bufferGraphics.drawString(""+stationaryWords ,15,95); 



}//end of for loop
// [1]"then copy the off-screen buffer onto the screen"
              
        g.drawImage(buffer, 0, 0, this);
        }
}//end of program

