/* This applet creates an animated display by summing four sine waves into an array. Example FPS rates are at http://rsb.info.nih.gov/nih-image/java/benchmarks/plasma.html. It is based on "Sam's Java Plasma Applet" (http://www.dur.ac.uk/~d405ua/Plasma.html) by Sam Marshall (t-sammar@microsoft.com). It was modified to use 8-bit images by Menno van Gangelen (M.vanGangelen@element.nl). */ import java.awt.*; import java.awt.image.*; public class Plasma extends java.applet.Applet implements Runnable { Image img; Thread runThread; long firstFrame, frames, fps; int width, height; int w,h,size; int scale=3; boolean showFPS = true; IndexColorModel icm; int[] waveTable; byte[][] paletteTable; byte[] pixels; public void init() { width = size().width; height = size().height; String p = getParameter("scale"); if (p != null) scale = Integer.parseInt(p); p = getParameter("showfps"); if (p != null) showFPS = p.equals("true"); w = width/scale; h = w; size = (int) ((w+h)/2)*4; pixels = new byte[w*h]; waveTable = new int[size]; paletteTable = new byte[3][256]; calculatePaletteTable(); img=createImage(new MemoryImageSource(w,h,icm,pixels,0,w)); } public void start() { if (runThread == null) { runThread=new Thread(this); runThread.start(); firstFrame=System.currentTimeMillis(); frames = 0; }; } public void stop() { if (runThread != null) { runThread.stop(); runThread=null; } } public void update(Graphics g) { img.flush(); g.drawImage(img, 0, 0, width, height, null); if (showFPS) { frames++; fps = (frames*10000) / (System.currentTimeMillis()-firstFrame); g.drawString(fps/10 + "." + fps%10 + " fps", 2, height - 2); } } void calculateWaveTable() { for(int i=0;i