//===================================================================== // File: RosslerCanvas.java // //===================================================================== import java.awt.*; public class RosslerCanvas extends Canvas { //=================================================================== // Variables // //=================================================================== private Rossler equation; private double domainxMax, domainxMin, domainyMax, domainyMin; private int windowxPos, windowyPos; private int oldWindowxPos, oldWindowyPos; private Image pilt, sahver; private Graphics piltg, sahverg; //=================================================================== // Methods // //=================================================================== //=================================================================== // Constructor // // Construct a rossler canvas with all values set to zero. //=================================================================== public RosslerCanvas() { super(); resize(400,300); equation = new Rossler(); } //=================================================================== // Accessors // //=================================================================== public void setParams(double a, double b, double c) { equation.setParams(a, b, c); pilt = null; piltg = null; } public void setInitialState(double t, double x, double y, double z) { equation.setInitialState(t, x, y, z); } public void setTimeStep(double step) { equation.setTimeStep(step); } //=================================================================== // SetDomain // // Set the section of phase space that the plot will show. //=================================================================== public void setDomain(double maxx, double minx, double maxy, double miny) { domainxMax = maxx; domainxMin = minx; domainyMax = maxy; domainyMin = miny; } //=================================================================== // restart // // Restart the oscillator from the initial state. //=================================================================== public void restart() { equation.reset(); pilt = null; sahver=null; windowxPos = mapxPoint(equation.getx()); windowyPos = mapyPoint(equation.gety()); oldWindowxPos = windowxPos; oldWindowyPos = windowyPos; } //=================================================================== // minimumSize: returns a minimum size for the canvas. //=================================================================== public Dimension minimumSize() { return new Dimension(400,350); } //=================================================================== // preferedSize: returns a good size for the canvas. //=================================================================== public Dimension preferredSize() { return new Dimension(600,600); } //=================================================================== // increment // // Increment the double well oscillator, map the new point onto the // window. //=================================================================== public void increment() { oldWindowxPos = windowxPos; oldWindowyPos = windowyPos; equation.increment(); windowxPos = mapxPoint(equation.getx()); windowyPos = mapyPoint(equation.gety()); if((sahver!=null)&&(sahverg!=null)){ sahverg.setColor(Color.blue); sahverg.drawLine(oldWindowxPos, oldWindowyPos, windowxPos, windowyPos); } repaint(); } //=================================================================== // update // // Update method for double buffering animation. //=================================================================== public void update(Graphics g) { if(pilt == null) { pilt = createImage(size().width, size().height); piltg = pilt.getGraphics(); piltg.setColor(getBackground()); piltg.fill3DRect(0, 0, size().width, size().height, false); } else { if(piltg == null) { piltg = pilt.getGraphics(); }} if(sahver == null) { sahver = createImage(size().width, size().height); sahverg = sahver.getGraphics(); sahverg.setColor(getBackground()); sahverg.fill3DRect(0, 0, size().width, size().height, false); } else { if(sahverg == null) { sahverg = sahver.getGraphics(); }} piltg.drawImage(sahver, 0, 0, this); piltg.setColor(Color.red); piltg.fillOval(windowxPos-5, windowyPos-5, 10, 10); g.drawImage(pilt, 0, 0, this); } //=================================================================== // paint // // Paint method for the canvas. //=================================================================== public void paint(Graphics g) { if(pilt!=null)g.drawImage(pilt, 0, 0, this); } //=================================================================== // Mouse Down : what to do when the mouse is pressed, destroy the // canvas, forcing it to be re-created blank. //=================================================================== public boolean mouseDown(Event evt, int x, int y) { pilt = null; return(true); } //=================================================================== // Mapping functions // // Map a point in phase space onto the window. //=================================================================== private int mapxPoint(double x) { return((int)((x-domainxMin) /(domainxMax-domainxMin)*(double)size().width)); } private int mapyPoint(double y) { return((int)(-(y-domainyMax) /(domainyMax-domainyMin)*(double)size().height)); } }