import ij.*; import ij.process.*; import ij.gui.*; import java.awt.*; import java.awt.image.*; import java.awt.event.*; import ij.plugin.frame.*; /* This plugin continuously generates and displays 640x480 images. It is plugin version of the "Plasma2" applet at "http://rsb.info.nih.gov/plasma2". */ public class Plasma_ extends PlugInFrame implements Runnable { boolean drawFPS = false; boolean noDisplay = false; boolean synch = true; boolean showFPS = true; int width = 640; int height =480; int w,h,size; Image img; MemoryImageSource source; Thread runThread; long firstFrame, frames, fps, frames2, fps2; IndexColorModel icm; int[] waveTable; byte[][] paletteTable; byte[] pixels; boolean running = true; public Plasma_() { super("Plasma"); WindowManager.addWindow(this); init(); setSize(width, height); GUI.center(this); setVisible(true); } public void init() { w = width/4; h = height/4; pixels = new byte[width*height]; size = (int) ((w+h)/2)*4; waveTable = new int[size]; paletteTable = new byte[3][256]; calculatePaletteTable(); source=new MemoryImageSource(width, height, icm, pixels, 0, width); source.setAnimated(true); source.setFullBufferUpdates(true); img=createImage(source); setForeground(Color.white); setFont(new Font("SansSerif", Font.PLAIN, 14)); start(); } public void start() { if (runThread == null) { runThread=new Thread(this, "Plasma"); runThread.start(); firstFrame=System.currentTimeMillis(); frames = 0; frames2 = 0; }; } public void stop() { running = false;; runThread = null; } public void update(Graphics g) { paint(g); } public void paint(Graphics g) { source.newPixels(); g.drawImage(img, 0, 0, null); if (showFPS) { frames++; if (System.currentTimeMillis()>firstFrame+4000) { firstFrame=System.currentTimeMillis(); fps = frames; fps2 = frames2; frames = 0; frames2 = 0; } if (drawFPS) g.drawString((int)((fps+0.5)/4) + " fps ("+(int)((fps2+0.5)/4)+")", 10, 50); else showFPS(); } } void calculateWaveTable() { for(int i=0;ifirstFrame+4000) { firstFrame=System.currentTimeMillis(); fps=frames; frames=0; } IJ.showStatus((int)((fps+0.5)/4) + " fps"); } public void windowClosing(WindowEvent e) { if (e.getSource()!=this) return; stop(); IJ.wait(500); setVisible(false); dispose(); WindowManager.removeWindow(this); } //public void processWindowEvent(WindowEvent e) { //super.processWindowEvent(e); // if (e.getID()==WindowEvent.WINDOW_CLOSING) // stop(); //} }