// (C) 2001 SyGem Software import java.awt.*; import java.applet.*; import com.sygem.jazz3d3.*; import com.sygem.jazz3d3.primitive.Torus3d; public class plasma extends Applet implements Runnable { Thread m_ce; World myWorld; int light1; int pid; boolean stat = false; Texture t2; int[] r = new int[64*64]; int[] g = new int[64*64]; int[] plasmapal = new int[256]; int[] cost = new int[256]; int a1,a2,a3,a4,b1,b2,b3,b4; int downx = 0; int downy = 0; double ddx = 0; double ddy = 0; boolean down = false; boolean antialias = false; boolean bilinear = false; //Construct the applet public plasma() { } //Initialize the applet public void init() { myWorld = new World(this); setLayout(new BorderLayout()); add("Center",myWorld); myWorld.setDelay(1); t2 = new Texture(Texture.VSMALL); initPlasma(); myWorld.setBackground(t2); RenderTextured tex = new RenderTextured(); tex.setTexture(t2); tex.setDrawingMode(Render.GOURAUD); Torus3d sp1 = new Torus3d(0.5,0.2,0.2,15,15,0,0,8); sp1.setRenderer(tex); pid = myWorld.addObject(sp1); Light l1 = new Light(0,0,1); myWorld.addLight(l1); } //Start the applet public void start() { if (m_ce == null) { m_ce = new Thread(this); m_ce.start(); } } //Stop the applet public void stop() { if (m_ce != null) { m_ce.stop(); m_ce = null; } } //Destroy the applet public void destroy() { } public void run() { int iCount = 0; long lTime0 = System.currentTimeMillis(); double z; ddx = 0.16; ddy = 0.35; z = 0.21; myWorld.prep(); m_ce.setPriority(Thread.MAX_PRIORITY); while (true) { myWorld.getParentObject(pid).rotateWorld(ddy,ddx,z); myWorld.prepareCanvas(); t2.setTextureArray(plasma()); myWorld.updateBackgroundImage(); myWorld.generateImage(); myWorld.drawImage(); myWorld.finishCanvas(); } } public boolean mouseDown(Event evt, int x, int y) { downx = x; downy = y; down = true; return true; } public boolean mouseUp(Event evt, int x, int y) { down = false; return true; } public boolean mouseDrag(Event evt, int x, int y) { if (down) { double dx = x - downx; double dy = y - downy; ddx = (dx / (this.size().width))*10.0; ddy = (dy / (this.size().height))*10.0; } return true; } public boolean keyDown(Event evt,int key) { if ((char)key=='a') {antialias=!antialias; myWorld.setAntiAliasing(antialias); return true; } if ((char)key=='b') {bilinear=!bilinear; myWorld.setBilinear(bilinear); return true; } return true; } void initPlasma() { for (int x=1; x<=32; x++) { plasmapal[x-1] = c(255,0,x*8-1); /* red - purple*/ plasmapal[x+32-1] = c(255,x*8-1,255); /* purple - white */ plasmapal[x+64-1] = c(255,255,255); /* white - white */ plasmapal[x+96-1] = c(255,255,255-(x*8-1)); /* white - yellow */ plasmapal[x+128-1] = c(255-(x*8-1),255,0); /* yellow - green */ plasmapal[x+160-1] = c(x*8-1,255-(x*8-1),x*8-1); /* green - ??? */ plasmapal[x+192-1] = c(255-(x*8-1),0,255); plasmapal[x+224-1] = c(x*8-1,0,255-(x*8-1)); } for(int t=0;t<256;t++) cost[t] = (int)( 63 * Math.cos(t * (3.14159/128) ) ); a1=a2=a3=a4=0; b1=(int)(Math.random() * 256); b2=(int)(Math.random() * 256); b3=(int)(Math.random() * 256); b4=(int)(Math.random() * 256); } int[] plasma() { a1 = b1; a2 = b2; int pos=0; for(int y=0;y<64;y++) { /* Initialize with outer variables */ a3 = b3; a4 = b4; for(int x=0;x<64;x++) { if (a1>255) a1 = a1-255; if (a1<0) a1 = a2+255; if (a2>255) a2 = a2-255; if (a2<0) a2 = a2+255; if (a3>255) a3 = a3-255; if (a3<0) a3 = a3+255; if (a4>255) a4 = a4-255; if (a4<0) a4 = a4+255; int a = cost[a1] + cost[a2] + cost[a3] + cost[a4]; g[pos++] = (a<0) ? 0 : a; /* Higher values result in many slower plasmas */ a3 += 1; a4 += 2; } /* Same as the previous comment*/ a1 += 2; a2 += 1; } /* ** Increment the outer variables. The higher these vars are ** incremented, the faster is the plasma. */ b1 += 1; b2 -= 2; b3 -= 1; b4 += 3; if (b1>255) b1 = b1-255; if (b2<0) b2 = b2+255; if (b3<0) b3 = b3+255; if (b4>255) b4 = b4-255; for (int i=0;i