import java.awt.*; /** Program: SmMovie7 Purpose: @author: Paul Garrett, garrett@math.umn.edu @version: 7, Sun Jan 26 16:22:12 CST 1997 */ /* * For efficiency, two arrays are kept, which _alternate_ (depending upon * parity of the time, between being the _actual_ wave and being * the _previous_ state */ public class SmMovie7 extends java.applet.Applet implements Runnable { final Color bgColor = Color.darkGray; final Color fgColor = Color.white; final int totalTime = 300; final int waveSpeed = 1; final int numberIntervals = 100; final double theFrac = 0.45; // = wave height / half of theHeight final double m = 0.005; // change: edit final double b = 0.005; // ad hoc Thread timerThread; int theTime; boolean queryMouseDown, queryRunMovie; double[][] theWave; // the native numbers int timeParity; // for evolving wave... int[][] theFrames; // to screen: [time][space] int[] xs; Image offScreenImage; Graphics offScreenGraphics; Button runButton, rewindButton; // first is Run/Freeze/Continue Label theLabel; // for warning about computational delay int theWidth, theHeight; // double maxValue, minValue; // u_tt - u_xx + m^2u + bu^3 =0 is Klein-Gordon... // and \int_x (1/2)(u_t^2 + u_x^2) + m^2 u^2/2 + b u^4/4 dx is conserved public void init() { initConstants(); initWave(); initFrame(); repaint(); } final void initConstants() { theTime=0; runButton = new Button("Run"); add(runButton); theLabel = new Label("After hitting \"run\", please allow time for the initial computation"); add(theLabel); queryMouseDown = false; queryRunMovie = false; theHeight = this.size().height; // to save time... theWidth = this.size().width; offScreenImage = createImage(theWidth, theHeight); offScreenGraphics = offScreenImage.getGraphics(); initXs(); // after get theWidth, theHeight theWave = new double[2][numberIntervals + 1]; theFrames = new int[totalTime+1][numberIntervals + 1]; } final void initWave() { int w = numberIntervals/4; for (int i=1; i < 2 * w; i++) { theWave[0][i] = theWave[1][i+1] = Math.exp(- ((float)((i-w)*(i-w)) * .02 ) ); } // sets up pseudo-travelling wave to right } public synchronized void paint(Graphics g) { drawOneFrame(); g.drawImage(offScreenImage, 0, 0, this); } final void drawOneFrame() { offScreenGraphics.setColor(bgColor); offScreenGraphics.fillRect(0, 0, theWidth, theHeight); offScreenGraphics.setColor(fgColor); for (int i=0; i