Java Kali Code - Written Long Ago this Program Created a Kaleidoscope... but JAVA Changed the Language and all Old Programs fail to Run Now...

Tye Dye Squiral Java Program Running by gvan42 gregvan


SOMEDAY... I Ought to Re Compile this Code and FIX the Errors & Make the Program Work Again... But I Kinda Doubt that will ever happen... 

 /**tds(number).java by gregvan

code for embedding in webpage....
<applet code="tds(number).class" 
height=500 width=750> </applet>
 **/

import java.applet.*;
import java.awt.*;
//~~~~~~make sure this name is exactly the same as filename~~~~~
public class tds29 extends Applet implements Runnable
{
int spin;
int tiny=1;
int tim=1;
int timFact=1;
int joe=10;
int joeFact=1;
int sd=1;
int sdFact=1;
int god;
int godFact=1;
int mod;
int god1;
int mod1;
int modFact=1;
int q=2;
int xx,yy;
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 w,ww;
int wwf=1;
int wf=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);
xx=gg-128;
yy=rr-128;

w=(int)(Math.random() *8);
ww=(int)(Math.random() *13);

               repaint();
               try
               {Thread.sleep(1000);}
               catch(InterruptedException e) {} 

               while (myRunner != null)
               {
                  repaint(); 
                  try
                  {Thread.sleep(100); }
                  catch (InterruptedException e) {}
               }  
           } 
        }
//~~~~~~~~drawing squares stuff~~~~~~~~~~~~~~~
public void drawSquares1(int cx,int cy,int xx,int yy,int q)
        {

bufferGraphics.fillRect(cx-xx-q,cy-yy-q,q+q,q+q);
bufferGraphics.fillRect(cx+xx-q,cy+yy-q,q+q,q+q);
bufferGraphics.fillRect(cx-yy-q,cy+xx-q,q+q,q+q);
bufferGraphics.fillRect(cx+yy-q,cy-xx-q,q+q,q+q);

bufferGraphics.fillRect(cx-xx+yy-q,cy-xx-yy-q,q+q,q+q);
bufferGraphics.fillRect(cx+xx+yy-q,cy-xx+yy-q,q+q,q+q);
bufferGraphics.fillRect(cx+xx-yy-q,cy+xx+yy-q,q+q,q+q);
bufferGraphics.fillRect(cx-xx-yy-q,cy+xx-yy-q,q+q,q+q);

}

public void drawSquares2(int cx,int cy,int xx,int yy,int q)
        {
q=q+1;

bufferGraphics.drawRect(cx-xx-q,cy-yy-q,q+q,q+q);
bufferGraphics.drawRect(cx+xx-q,cy+yy-q,q+q,q+q);
bufferGraphics.drawRect(cx-yy-q,cy+xx-q,q+q,q+q);
bufferGraphics.drawRect(cx+yy-q,cy-xx-q,q+q,q+q);

bufferGraphics.drawRect(cx-xx+yy-q,cy-xx-yy-q,q+q,q+q);
bufferGraphics.drawRect(cx+xx+yy-q,cy-xx+yy-q,q+q,q+q);
bufferGraphics.drawRect(cx+xx-yy-q,cy+xx+yy-q,q+q,q+q);
bufferGraphics.drawRect(cx-xx-yy-q,cy+xx-yy-q,q+q,q+q);
if(gg<bb){
bufferGraphics.drawLine(cx-xx,cy-yy,cx-yy,cy+xx);
bufferGraphics.drawLine(cx-xx,cy-yy,cx+yy,cy-xx);
bufferGraphics.drawLine(cx+xx,cy+yy,cx-yy,cy+xx);
bufferGraphics.drawLine(cx+xx,cy+yy,cx+yy,cy-xx);
}
if(bw>rr){
bufferGraphics.drawLine(cx-xx,cy-yy,cx,cy);
bufferGraphics.drawLine(cx+xx,cy+yy,cx,cy);
bufferGraphics.drawLine(cx-yy,cy+xx,cx,cy);
bufferGraphics.drawLine(cx+yy,cy-xx,cx,cy);

bufferGraphics.drawLine(cx-xx+yy,cy-xx-yy,cx,cy);
bufferGraphics.drawLine(cx+xx+yy,cy-xx+yy,cx,cy);
bufferGraphics.drawLine(cx+xx-yy,cy+xx+yy,cx,cy);
bufferGraphics.drawLine(cx-xx-yy,cy+xx-yy,cx,cy);
}
q=q-1;
}
//~~~end of drawing squares stuff~~~~~~~~~~~~~~~

       // 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)
        {
mod=mod+modFact;
if(mod>9){modFact=-1;}
if(mod<-9){modFact=1;}

//~~~~~~~tim is inside god~~~~~~~~
god=god+godFact;
if(god>12){godFact=-1;}
if(god<-12){godFact=1;

tim=tim+timFact;
if (tim>5){timFact=-1;}
if(tim<2){timFact=1;}

}//end of god

//-----------size of squares---------
sd=sd+sdFact;
if (sd > 12){sdFact=-1;}
if(sd<3){sdFact=1;}

tiny=tiny+1;
if(tiny>rr){tiny=-(rr+rr);}

joe=joe+joeFact;
if(joe>12){joeFact=-1;}
if(joe<3){joeFact=1;}

spin=spin+1;
if(spin>20){
spin=1;
for (int i3=0; i3<gg;i3++){
mod1=mod1+1;
if(mod1>10){mod1=-10;}
god1=god1+1;
if(god1>9){god1=-9;}
}}

//----------------------------------for loop--------------------------------
//for loop to paint many images before sleeping .1 second     
       for (int i=0;i<3;i++)
        {

             //color changer up counters
if(god>mod){
 rr=rr+1;
           if(rr>255){rr=1;}
gg=gg+2;
           if(gg>255){gg=1;}
bb=bb+3;
           if(bb>255){bb=1;}
bw=bw+4;
           if(bw>255){bw=1;}
}
if(god<=mod){
rr=rr+rq;
if(rr>252){rq=-1;}
if(rr<3){rq=1;}
gg=gg+gq;
if(gg>251){gq=-1;}
if(gg<4){gq=1;}
bb=bb+bq;
if(bb>250){bq=-1;}
if(bb<5){bq=1;}
bw=bw+bwq;
if(bw>249){bwq=-1;}
if(bw<6){bwq=1;}
}          
//-------------------position xx,yy----------------
w=w+wf;
if (w>12+mod){wf=-1;}
if (w<-(11+mod)){wf=1;}

ww=ww+wwf;
if(ww>11+god){wwf=-1;}
if(ww<-(12+god)){wwf=1;}
if(tiny<=0 && tiny>-rr){             
xx=xx+w;
yy=yy+ww;
}
if(tiny>0){
xx=xx+mod;
yy=yy+god;}
if(tiny<=-rr){
xx=xx+mod1;
yy=yy+god1;}

//~~~~~~~~~~check to see if off screen~~~~~~~~

if(xx>cx+100){xx=0;
yy=0;}
if(yy>cx+100){yy=0;
xx=0;}
if(xx<-(cx+100)){xx=0;
yy=0;}
if(yy<-(cx+100)){yy=0;
xx=0;}

//-----------for loop ii--------------
if(tiny<0){
joe=joe+joeFact;
if(joe>12){joeFact=-1;}
if(joe<3){joeFact=1;}
}
//for loop to paint many images     
       for (int ii=-(joe*tim);ii<((joe*tim)+1);ii=ii+joe)
        {
q=sd;
if (tiny>0){q=5;}
if(tiny<=-rr){q=mod1+10;}

xx=xx+ii;
if(tiny>=-rr){yy=yy-ii-ii;}
if(tiny<-rr){yy=yy+ii;}
//apply the new numbers for stars
        Color wNew = new Color(rr, gg, bb);
        bufferGraphics.setColor(wNew); 
//~~~~~call subroutine~~~~~~~~
drawSquares1(cx,cy,xx,yy,q);
//~~~~~~~~~~~~~~~~~~`~
//apply the new numbers for stars
        Color waxNew = new Color(256-rr, 256-gg, bb);
        bufferGraphics.setColor(waxNew); 
//~~~~call subroutine~~~~~~~~~~
drawSquares2(cx,cy,xx,yy,q);
//~~~~~~~~~~~~~~~~~`~

//~~~~~~~~~other set of squares~~~~~~~~~~
//apply the new numbers for black erase
        Color zNew = new Color(bw,bw,bw);
        bufferGraphics.setColor(zNew);
//~~~~~~~~~calculate difference~~~~~~~~~~~

xx=xx+25;
yy=yy+25;
//~~~~call subroutine~~~~~~
drawSquares1(cx,cy,xx,yy,q);
//~~~~~~~~~~~~~~~~`~
//apply the new numbers for squares
        Color zapNew = new Color(bw,rr,256-bb);
        bufferGraphics.setColor(zapNew);
//~~~call subroutine~~~~~~~~~
drawSquares2(cx,cy,xx,yy,q);
//~~~~~~~~~~~~~~~~`~
xx=xx-25;
yy=yy-25;

//~~~~~~~~~~~~~~~~`~
if(xx>yy){
//apply the new numbers for black erase
        Color zapBNew = new Color(gg,bw,bw);
        bufferGraphics.setColor(zapBNew);
}
//~~~~~~~~~~~~~~~~`~
if(xx<=yy){
//apply the new numbers for black erase
        Color zapCNew = new Color(0,0,0);
        bufferGraphics.setColor(zapCNew);
}
xx=xx+100;
yy=yy+100;
//~~~call subroutine~~~~~~~~~
drawSquares1(cx,cy,xx,yy,q);
//~~~~~~~~~~~~~~~~`~
yy=yy-100;
xx=xx-100;
xx=xx+200;
yy=yy+200;
//~~~call subroutine~~~~~~~~~
drawSquares1(cx,cy,xx,yy,q);
//~~~~~~~~~~~~~~~~`~
yy=yy-200;
xx=xx-200;
xx=xx-125;
yy=yy-125;
//~~~call subroutine~~~~~~~~~
drawSquares1(cx,cy,xx,yy,q);
//~~~~~~~~~~~~~~~~`~
yy=yy+125;
xx=xx+125;
xx=xx-225;
yy=yy-225;
//~~~call subroutine~~~~~~~~~
drawSquares1(cx,cy,xx,yy,q);
//~~~~~~~~~~~~~~~~`~
yy=yy+225;
xx=xx+225;


xx=xx-ii;
if(tiny>=-rr){yy=yy+ii+ii;}
if(tiny<-rr){yy=yy-ii;}
}//end of for 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...

Popular Posts

Popular Posts