/** * Bounce Graph Class for Rob's * Difference Equation Iteration Demonstrator Applet * @author Robert J Morton UK-YE572246C * @version 27 November 1997 modified 07 August 2009, 18 April 2012 */ /* FORMULA ITERATION CLASS. */ class formula { private double x = 0.01, // the iterated variable c = 3.68, // the formula scaling constant P1 = 0, // upper real range limit of graph area P2 = 1, // lower real range limit of graph area δP = 0.01; // real x-increment for drawing the parabola boolean InRange = true, // indicates if x goes off the graph EqnFlag = false; // which of the 2 equations is being used private difeqnap ap; // instance reference to the main applet class private bouncegr bg; // instance reference to the bounce-graph class private setbutt sb; // instance reference to the setbutt class /* construct the bounce graph resources by passing the instance reference of the main applet class. */ formula(difeqnap ap) { this.ap = ap; } // Set the instance reference of the setbutt class. void setSB(setbutt sb) {this.sb = sb;} // Set the instance reference of the bounce-graph class. void setBG(bouncegr bg) {this.bg = bg;} void setEF(boolean b) {EqnFlag = b;} // set which equation is in force // Allows the Cval panel to set the current C-value. void setC(double c) {this.c = c;} void reset() { // PRIME/RESET THE BOUCE GRAPH FORMULA if(EqnFlag) { // IF USING X = X**2 + C P1 = -2; // upper real range limit of graph area P2 = +2; // lower real range limit of graph area δP = .005; // real x-increment for drawing the parabola x = 0; // initial value of x } else { // IF USING X = CX(1 - X) P1 = 0; // upper real range limit of graph area P2 = 1; // lower real range limit of graph area δP = .001; // real x-increment for drawing the parabola x = 0.01; // initial value of x } InRange = true; // assume x is not out of range to start with } /* The following loop increments the real variables for plotting the parabola for the initial drawing of the bounce-graph. On each pass of the loop it calls the plotParabola() method in the bounce- graph class to do each plot in pixel units. */ void plotParabola() { // DRAW THE PARABOLA double x, y; // horizontal and vertical real variables // for each small step along the horizontal axis ... for(x = P1 ; x <= P2 ; x += δP) { /* If the equation switch flag is set TRUE, use the square law equation; otherwise, use standard logistics equation. */ if(EqnFlag) y = x * x + c; else y = c * x * (1 - x); // Provided 'y' is within range of graph area do plot in pixel units. if(y >= P1 && y <= P2) bg.plotParabola(x, y); } } void iterate() { // DO ONE ITERATION OF THE SELECTED FORMULA /* If the equation switch flag is set TRUE, use the square law equation; otherwise, use standard logistics equation. */ if(EqnFlag) x = x * x + c; else x = c * x * (1 - x); if(x < P1 || x > P2) { // if out of range of graph area InRange = false; // set to 'out of range' sb.Stop(); // stop the iteration process ap.showStatus( "Stopped because x has gone out of range of the graph." ); } } double getX() {return x;} // get the [iterated i.e. updated] value of x // Is 'x' still within the range of the graph area boolean inRange() { return InRange; } }