/** * Bounce Graph Class for Rob's * Difference Equation Iteration Demonstrator Applet * @author Robert J Morton * @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 formula(difeqnap ap) { // construct the bounce graph resources this.ap = ap; // instance reference to the main applet class } void setSB(setbutt sb) { this.sb = sb; // set instance reference to setbutt class } void setBG(bouncegr bg) { this.bg = bg; // set instance reference to bounce-graph } void setEF(boolean b) { EqnFlag = b; // set which equation is in force } void setC(double c) { this.c = c; // current C-value set by the Cval panel } 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 plot- ting 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(EqnFlag) // if equation switch flag set true y = x * x + c; // use the square law EqnFlag else // else [equation switch flag set false] y = c * x * (1 - x); // use standard logistics equation if(y >= P1 && y <= P2) // provided y is within range of graph area bg.plotParabola(x, y); // do plot in pixel units } } void iterate() { // DO ONE ITERATION OF THE SELECTED FORMULA if(EqnFlag) // if equation switch flag set true x = x * x + c; // use the square law EqnFlag else // if equation switch flag set false x = c * x * (1 - x); // use standard logistics equation 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 System.out.println("formula.java: Stopped because x has"); System.out.println("gone out of range of the graph."); } } double getX() { return x; // get the [iterated i.e. updated] value of x } boolean inRange() { return InRange; // is x still within the range of the graph area? } }