/**octet.java by gregvan * RECOMMENDED SIZE: height 400, width 600 **/ import java.applet.*; import java.awt.*; public class selfhypnosis2 extends Applet implements Runnable { int rr,gg,bb,xray;//color variables int rq=1; // color up-down counters int gq=1; int bq=1; int x, y; //endpoint locations int z; int a; int zz=1; //endpoint up-down counters int xx=2; int yy=3; int aa=4; int w=1; //width between lines int wf=1; int hh,ii,jj,kk; String yourWords; Thread myRunner; Color cNew = new Color(125, 0, 255); Color dNew = new Color(0, 0, 0); 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(); yourWords=getParameter("yw"); if (yourWords==null){yourWords="";} } 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() *400); x=x-200; y=(int)(Math.random() *300); y=y-150; z=(int)(Math.random() *500); z=z-250; repaint(); try {Thread.sleep(1000);} catch(InterruptedException e) {} while (myRunner != null) { repaint(); try {Thread.sleep(100); } catch (InterruptedException e) {} } } } // 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) { w=w+wf; if (w>200){wf=-1;} if (w<2){wf=3;} //for loop to paint 7 images before sleeping .1 second for (int i=0;i<7;i++) { //color changer up-down counters rr=rr+rq; if(rr>251){rq=-1;} if(rr<4){rq=1;} gg=gg+gq; if(gg>252){gq=-2;} if(gg<3){gq=2;} bb=bb+bq; if(bb>250){bq=-3;} if(bb<5){bq=3;} xray=xray+16; if(xray>255){xray=0;} //move the endpoints of the lines //up-down counters z=z+zz; if(z>400){zz=-1;} if(z<-400){zz=4;} a=a+aa; if(a>300){aa=-2;} if(a<-300){aa=1;} x=x+xx; if(x>350){xx=-3;} if(x<-350){xx=1;} y=y+yy; if(y>250){yy=-1;} if(y<-250){yy=5;} hh=hh+1; if (hh>50){hh=-50;} ii=ii+1; if(ii>60){ii=-60;} jj=jj-1; if(jj<-80){jj=80;} kk=kk+1; if(kk>100){kk=-100;} for (int i2=-w;i2<1;i2=i2+w) { x=x+i2+i2; y=y-i2-i2; a=a-i2; z=z+i2; //apply the new numbers for color Color cNew = new Color(rr, gg, bb); bufferGraphics.setColor(cNew); //draw the lines set 1 bufferGraphics.drawLine(300+ x,200+ y,300+ z,200+a); bufferGraphics.drawLine(300- x,200- y,300- z,200-a); bufferGraphics.drawLine(300+ x,200- y,300+ z,200-a); bufferGraphics.drawLine(300- x,200+y,300- z,200+a); //draw the lines set 2 bufferGraphics.drawLine(300+ y,200+ x,300+ a,200+z); bufferGraphics.drawLine(300- y,200- x,300- a,200-z); bufferGraphics.drawLine(300+ y,200- x,300+ a,200-z); bufferGraphics.drawLine(300- y,200+x,300- a,200+z); if(w>100){ //black and white lines Color dNew = new Color(bb, bb, bb); bufferGraphics.setColor(dNew); } else { Color dNew = new Color(gg, bb, xray); bufferGraphics.setColor(dNew); } //draw the black and white lines in a slightly //different location... x=x+hh; y=y+ii; z=z-jj; a=a-kk; //draw the lines set 1 bufferGraphics.drawLine(300+ x,200+ y,300+ z,200+a); bufferGraphics.drawLine(300- x,200- y,300- z,200-a); bufferGraphics.drawLine(300+ x,200- y,300+ z,200-a); bufferGraphics.drawLine(300- x,200+y,300- z,200+a); //draw the lines set 2 bufferGraphics.drawLine(300+ y,200+ x,300+ a,200+z); bufferGraphics.drawLine(300- y,200- x,300- a,200-z); bufferGraphics.drawLine(300+ y,200- x,300+ a,200-z); bufferGraphics.drawLine(300- y,200+x,300- a,200+z); x=x-hh; //move ends back to where the were before y=y-ii; z=z+jj; a=a+kk; x=x-i2-i2; // do the opposite to restore... y=y+i2+i2; a=a+i2; z=z-i2; } //i2 loop end // draw a black diamond in the center to improve contrast Color eNew = new Color(0, 0, 0); bufferGraphics.setColor(eNew); bufferGraphics.drawLine(300+ x-y,200,300,200+x-y); bufferGraphics.drawLine(300+ x-y,200,300,200-x+y); bufferGraphics.drawLine(300- x+y,200,300,200+x-y); bufferGraphics.drawLine(300- x+y,200,300,200-x+y); //message... Color fNew = new Color(bb,rr, gg); bufferGraphics.setColor(fNew); bufferGraphics.setFont(new Font("Serif",Font.BOLD,50)); bufferGraphics.drawString (""+yourWords,40,225); }//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...