/**sqtrip.java by gregvan now resizeable! * RECOMMENDED SIZE: height 400, width 600 *or larger/smaller as you wish **/ import java.applet.*; import java.awt.*; public class asqtrip4 extends Applet implements Runnable { int pd;//repeat lines int cx,cy; //center of screen x and y int bw;//black and white variable int bwq=1;//b&w initial counter value int rr,gg,bb;//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; //new int joe,sue,suewow; int fred=1; 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 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) { gg=gg+gq; if(gg>252){gq=-2;} if(gg<3){gq=2;} //for loop to paint 5 images before sleeping .1 second suewow=suewow+1; if (suewow>65){suewow=-9;} pd=pd+1; if(pd>5){pd=1;} for (int i=0;i<5;i++) { //color changer up-down counters rr=rr+rq; if(rr>253){rq=-1;} if(rr<2){rq=1;} bb=bb+bq; if(bb>250){bq=-3;} if(bb<5){bq=3;} //black and white changer bw=bw+bwq; if(bw>245){bwq=-1;} if(bw<10){bwq=2;} //move the endpoints of the lines //new joe=joe+fred; if (joe>10){fred=-1;} if(joe<-10){fred=1;} //up-down counters z=z+zz; if(z>400){zz=-1;} if(z<-400){zz=pd;} a=a+aa; if(a>325){aa=-1;} if(a<-325){aa=pd;} x=x+xx; if(x>350){xx=-pd;} if(x<-350){xx=1;} y=y+yy; if(y>375){yy=-pd;} if(y<-375){yy=1;} //apply the new numbers for color Color cNew = new Color(rr, gg, bb); bufferGraphics.setColor(cNew); //draw the lines set 1 bufferGraphics.drawLine(cx+ x-joe,cy+ y,cx+ z+joe,cy+y); bufferGraphics.drawLine(cx- x+joe,cy+ y,cx- z-joe,cy+y); //draw the lines set 1a bufferGraphics.drawLine(cx+ x-joe,cy- y,cx+ z+joe,cy-y); bufferGraphics.drawLine(cx- x+joe,cy- y,cx- z-joe,cy-y); //apply the new numbers for color Color tNew = new Color(gg, bb, rr); bufferGraphics.setColor(tNew); //draw the lines set 2 bufferGraphics.drawLine(cx+ z,cy+ x+joe,cx+ z,cy+a+joe); bufferGraphics.drawLine(cx- z,cy+ x+joe,cx- z,cy+a+joe); //draw the lines set 2a bufferGraphics.drawLine(cx+ z,cy- x-joe,cx+ z,cy-a-joe); bufferGraphics.drawLine(cx- z,cy- x-joe,cx- z,cy-a-joe); //black and white lines Color dNew = new Color(bw,bw,bw); bufferGraphics.setColor(dNew); //draw the lines set 1 bufferGraphics.drawLine(cx+ x-joe,cy+ y+pd,cx+ z+joe,cy+y-pd); bufferGraphics.drawLine(cx- x+joe,cy+ y+pd,cx- z-joe,cy+y-pd); //draw the lines set 1a bufferGraphics.drawLine(cx+ x-joe,cy- y-pd,cx+ z+joe,cy-y+pd); bufferGraphics.drawLine(cx- x+joe,cy- y-pd,cx- z-joe,cy-y+pd); //black and white lines Color vNew = new Color(256-bw,256-bw,256-bw); bufferGraphics.setColor(vNew); //draw the lines set 2 bufferGraphics.drawLine(cx+ z+pd,cy+ x+joe,cx+ z-pd,cy+a+joe); bufferGraphics.drawLine(cx- z-pd,cy+ x+joe,cx- z+pd,cy+a+joe); //draw the lines set 2a bufferGraphics.drawLine(cx+ z+pd,cy- x-joe,cx+ z-pd,cy-a-joe); bufferGraphics.drawLine(cx- z-pd,cy- x-joe,cx- z+pd,cy-a-joe); }//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...