import ChaosDemos.*; import java.awt.*; import java.util.*; import java.net.URL; import graph.*; /** * Iterates and plots the chaos models described by coupled ODEs.
* Uses the "Java Graph Class Library" by Leigh Brookshaw * @version 3 August, 1997 * @author Michael Cross */ public class Odes extends dynamicGraph { /** functions */ private static final int LORENZ=0; private static final int ROSSLER=1; private static final int DUFFING=2; private static final int PENDULUM=3; private static final int VANDERPOHL=4; private static final int CHUA=5; /** plot types */ private static final int TIMESERIES=0; private static final int FOURIER=1; private static final int POINCARE=2; private static final int RETURNMAP=3; private static final int MAXMAP=4; private static final int RECONSTRUCT=5; private static final double Pi2=2*Math.PI; /* classes used */ private startOdes outerparent; superGraph2D graph; private movie theMovie; ode solver; private OdesDiagnostics diagnostics; private powerSpectrum mySpectrum; OdesFunction odesFunction; /* animation thread */ Thread aThread=null; /* GUI classes */ textControls variables,parameters; buttonControls buttons; choiceControls choices; Panel topRightPanel; Choice plotChoice; Choice functionChoice; Label status; /* items for plotting points */ private URL markerURL; /** location of marker.txt */ URL documentBase; /** input marker size */ double marker=1.; /** marker size */ double markerScale; /** type of marker (see marker.txt) */ int markerType; /** true after first mouse click */ boolean clicked=false; /** true if time to be displayed */ boolean showTime=true; /** true if ghost to be showed */ boolean showGhost=false; private boolean dummy; /** number of variables (icluding time) */ int nVariables=4; /** number of curves */ int ncurve=-1; /** plot type */ int plot=0; /** function type */ int function=0; double ghostTime; int delay; double xmin=0,xmax=1,ymin=0,ymax=1; double xmouse=0,ymouse=0; /* parameters */ /** function parameter */ double a[]={28.,2.667,10.,0.}; /** color of ghost */ Color transientColor; /* default values depending on function and/or plot */ private String[] axisLabel={"Time"," X "," Y "," Z "}; /** * @param target starting class * @see startLor */ Odes(startOdes target, URL in_documentBase) { documentBase=in_documentBase; graph = new superGraph2D(this); graph.borderRight=35; try { markerURL = new URL(documentBase,"marker.txt"); graph.setMarkers(new Markers(markerURL)); } catch(Exception e) { System.out.println("Failed to create Marker URL!"); } theMovie = new movie(this); solver = new ode((dynamicGraph) this, nVariables); this.outerparent = target; GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints constraints = new GridBagConstraints(); setLayout(gridbag); constraints.fill=GridBagConstraints.BOTH; constraints.gridheight = 1; constraints.gridwidth=1; constraints.weighty = 1.0; constraints.weightx=0.75; constraints.insets = new Insets(0,0,0,10); Panel leftPanel = new Panel(); leftPanel.setLayout(new BorderLayout()); leftPanel.add("Center",graph); Panel bottomLeftPanel = new Panel(); bottomLeftPanel.setLayout( new GridLayout(2,1)); bottomLeftPanel.add(theMovie); String[] buttonLabels={" Reset "," Clear ", " Start "," Stop "}; buttons = new buttonControls((dynamicGraph) this, buttonLabels,buttonLabels.length,true); buttons.b_init[0] = true; buttons.b_stopped[3] = false; buttons.b_started[1] = true; buttons.b_started[3] = true; buttons.setup(); bottomLeftPanel.add(buttons); leftPanel.add("South",bottomLeftPanel); constraints.insets = new Insets(0,0,10,0); gridbag.setConstraints(leftPanel, constraints); add(leftPanel); Panel rightPanel = new Panel(); rightPanel.setLayout(new BorderLayout()); constraints.weightx=0.25; constraints.insets = new Insets(0,0,15,10); gridbag.setConstraints(rightPanel, constraints); add(rightPanel); topRightPanel = new Panel(); topRightPanel.setLayout(gridbag); constraints.gridheight = 3; constraints.gridwidth=1; constraints.weightx=1.; constraints.weighty = 0.75; constraints.insets = new Insets(0,0,0,10); constraints.fill=GridBagConstraints.NONE; String[] textboxes = {String.valueOf(a[0]),String.valueOf(a[1]), String.valueOf(a[2]),String.valueOf(a[3]),"0.01", "1","2"}; String[] labels = {" a"," b"," c"," d", " dt","x-ax","y-ax"}; parameters = new textControls((dynamicGraph)this,textboxes,labels,textboxes.length,5); gridbag.setConstraints(parameters, constraints); topRightPanel.add(parameters); String[] textboxes1 = {"2","5","20","10","0.","0.","0."}; String[] labels1 = {" X0"," Y0"," Z0"," trans "," dX0", " dY0"," dZ0"}; variables = new textControls((dynamicGraph) this,textboxes1,labels1,textboxes1.length,5); constraints.gridwidth = GridBagConstraints.REMAINDER; constraints.insets = new Insets(0,0,0,10); gridbag.setConstraints(variables, constraints); topRightPanel.add(variables); functionChoice = new Choice(); functionChoice.addItem("Lorenz"); functionChoice.addItem("Rossler"); functionChoice.addItem("Duffing"); functionChoice.addItem("Pendulum"); functionChoice.addItem("VanDerPohl"); functionChoice.addItem("Chua"); constraints.gridwidth=1; constraints.weighty = 0.2; constraints.gridheight=1; constraints.gridwidth=GridBagConstraints.REMAINDER; constraints.insets = new Insets(0,0,0,0); gridbag.setConstraints(functionChoice, constraints); topRightPanel.add(functionChoice); plotChoice = new Choice(); plotChoice.addItem("Time Series"); plotChoice.addItem("Spectrum"); plotChoice.addItem("Poincare"); plotChoice.addItem("Return Map"); plotChoice.addItem("Max Map"); plotChoice.addItem("Reconstruct"); constraints.gridwidth=1; constraints.weighty = 0.2; constraints.gridheight=1; constraints.gridwidth=GridBagConstraints.REMAINDER; constraints.insets = new Insets(0,0,0,0); gridbag.setConstraints(plotChoice, constraints); topRightPanel.add(plotChoice); String[] choiceLabels={"Show Ghost: ","Allow Sleep: ","Show Time: "}; choices = new choiceControls((dynamicGraph) this, choiceLabels); constraints.weighty = 0.25; constraints.gridheight = 1; gridbag.setConstraints(choices, constraints); topRightPanel.add(choices); choices.setState(0,false); theMovie.toSleep=true; choices.setState(1,true); // showTime=true; choices.setState(2,true); rightPanel.add("Center",topRightPanel); status=new Label(" "); rightPanel.add("South",status); transientColor=Color.white; if(target.inputParameters) { function=target.function; functionChoice.select(function); plot=target.plot ; plotChoice.select(plot); setFunctionDefaults(); setPlotDefaults(); if(target.showGhost) { choices.setState(0,true); showGhost=true; transientColor=Color.lightGray; } if(!target.showTime) { choices.setState(2,false); showTime=false; } for(int i=0;i