import java.applet.Applet; import t3d.Vector3D; import t3d.Particle; import t3d.Projector; import java.awt.Graphics; import java.awt.Dimension; import java.awt.Image; import java.awt.Color; import java.awt.Point; public class TestParticle extends Applet implements Runnable{ Thread t; boolean loopDone = false; Particle points[]; Projector pj; int max = 120; int width; int height; int hWidth; int hHeight; int lenzLength = 200; int bornNum = 6; int bornNumRand = 2; int distance = 150; Vector3D gravity; Graphics bg; Image bgImage; protected static final boolean DEBUG = false; public void init(){ Dimension r = size(); width = r.width; height = r.height; hWidth = (int)(width * 0.5); hHeight = (int)(height * 0.5); gravity = new Vector3D(0.0,-0.5,0.0); points = new Particle[max]; pj = new Projector(lenzLength); for (int i = 0 ; i < points.length ; i++){ points[i] = new Particle(0.0,0.0,0.0,0.0,0.0,0.0); } bgImage = createImage(width, height); bg = bgImage.getGraphics(); } public void start(){ if( t == null ){ t = new Thread(this); loopDone = true; for (int i = 0 ; i < points.length ; i++){ points[i].kill(); } t.start(); } } public void stop(){ if( t != null ){ loopDone = false; t.stop(); t=null; } } public void destroy(){ this.stop(); } public int searchEmptyPoint(int startnum){ for(int i = startnum;i< points.length ; i++){ if (!(points[i].isAlive())){ return i; } } return -1; } public void run (){ int i=0; double x,y,z; int px,py,px2,py2; int age; int bornNum2; int pCount; int emptyPoint; Point pixel; Point pixel2; Color cols[]; pixel = new Point(0,0); pixel2 = new Point(0,0); while (loopDone){ bg.setColor(Color.black); bg.fillRect(0,0,width,height); bg.setColor(Color.darkGray); for(i=0;i<10;i++){ x = i*20 - 100; pj.translate(x,50,-100+distance,pixel); pj.translate(x,50,100+distance,pixel2); bg.drawLine(pixel.x+hWidth,pixel.y+hHeight,pixel2.x+hWidth,pixel2.y+hHeight); } for(i=0;i<10;i++){ z = i*20 - 100; pj.translate(-100,50,z+distance,pixel); pj.translate(100,50,z+distance,pixel2); bg.drawLine(pixel.x+hWidth,pixel.y+hHeight,pixel2.x+hWidth,pixel2.y+hHeight); } x = 0.0 ; y = 0.0 ; z = 0.0; pj.translate(x,y+50,z+distance,pixel); bg.setColor(Color.white); bg.drawLine(pixel.x+hWidth,pixel.y+hHeight,pixel.x+hWidth,pixel.y+hHeight); bornNum2 = (int)(bornNum + Math.random() - 0.5 * 2 * bornNumRand); pCount = 0; for (i = 0;i