/* (c) 1996 B J Soares, J J O'Connor & E F Robertson. All rights reserved.

 * The Famous Curves interactive associated curve plotter in java

 * adapted from Pascal routines by J J O'Connor for The Mathematical MacTutor,

 * School of Mathematical and Computational Sciences, University of St Andrews

 * by Ben Soares for the Famous Curves section of the MacTutor History of

 * Mathematics Archive on the WWW at 

 *             http://www-groups.dcs-st-and.ac.uk/~history/

 * Please do not modify this code without the authors' permission.

 * The authors' email addresses are;

 * Ben Soares:    bs@st-and.ac.uk

 * John O'Connor: joc@st-and.ac.uk

 * Constructive comments are always welcome.

 * Whilst a reasonable amount of effort has been taken to make this a useful

 * application no responsibility for this code and its use will be taken by

 * the authors.

 */



import java.awt.*;

import java.applet.*;



public class FamousCurves extends Applet {



 Curve curve;

 CurvePanel curvepanel;

 CurveControls curvecontrols;

 String curvename;

 double tmin;

 double tmax;

 int numberofpoints;

 double td;

 boolean numberofpointsb = false;

 boolean tdb = false;

 double dt;

 double xb, xt, yb, yt;

 String supportedparameters;

 double a, b, c, d, e, f, h, k, m, n, p;

 boolean ap = false;

 boolean bp = false;

 boolean cp = false;

 boolean dp = false;

 boolean ep = false;

 boolean fp = false;

 boolean hp = false;

 boolean kp = false;

 boolean mp = false;

 boolean np = false;

 boolean pp = false;



 // beginning of initialisation method



 public void init() {



  this.curvename = "Ellipse";

  this.tmin = 0.0;

  this.tmax = 6.824;

  this.numberofpoints = 200;

  this.td = 0.03142;

  this.dt = 0.000001;

  this.xb = -5;

  this.xt = 5;

  this.yb = -5;

  this.yt = 5;  

  this.supportedparameters = "";

  this.a = 1.0;

  this.b = 0.5;

  this.c = 3.0;

  this.d = -4.0;

  this.e = 1;

  this.f = -1;

  this.h = 2;

  this.k = 2;

  this.m = 5;

  this.n = 3;

  this.p = 4/7;



  String curvenamestring = getParameter("curvename");

  String tminstring = getParameter("tmin");

  String tmaxstring = getParameter("tmax");

  String numberofpointsstring = getParameter("numberofpoints");

  String tdstring = getParameter("td");

  String dtstring = getParameter("dt");

  String xbstring = getParameter("xb");

  String xtstring = getParameter("xt");

  String ybstring = getParameter("yb");

  String ytstring = getParameter("yt");

  String supportedparametersstring = getParameter("supportedparameters");

  String astring = getParameter("a");

  String bstring = getParameter("b");

  String cstring = getParameter("c");

  String dstring = getParameter("d");

  String estring = getParameter("e");

  String fstring = getParameter("f");

  String hstring = getParameter("h");

  String kstring = getParameter("k");

  String mstring = getParameter("m");

  String nstring = getParameter("n");

  String pstring = getParameter("p");



  curvename = curvenamestring;

  if (tminstring != null) {

   try {

    this.tmin = Double.valueOf(tminstring).doubleValue();

   } catch (NumberFormatException e) {

   }

  }

  if (tmaxstring != null) {

   try {

    this.tmax = Double.valueOf(tmaxstring).doubleValue();

   } catch (NumberFormatException e) {

   }

  }

  if (numberofpointsstring != null) {

   try {

    this.numberofpoints = Integer.valueOf(numberofpointsstring).intValue();

    this.numberofpointsb = true;

   } catch (NumberFormatException e) {

   }

  }

  if (tdstring != null) {

   try {

    this.td = Double.valueOf(tdstring).doubleValue();

    this.tdb = true;

   } catch (NumberFormatException e) {

   }

  }

  if (dtstring != null) {

   try {

    this.dt = Double.valueOf(dtstring).doubleValue();

   } catch (NumberFormatException e) {

   }

  }

  if (xbstring != null) {

   try {

    this.xb = Double.valueOf(xbstring).doubleValue();

   } catch (NumberFormatException e) {

   }

  }

  if (xtstring != null) {

   try {

    this.xt = Double.valueOf(xtstring).doubleValue();

   } catch (NumberFormatException e) {

   }

  }

  if (ybstring != null) {

   try {

    this.yb = Double.valueOf(ybstring).doubleValue();

   } catch (NumberFormatException e) {

   }

  }

  if (ytstring != null) {

   try {

    this.yt = Double.valueOf(ytstring).doubleValue();

   } catch (NumberFormatException e) {

   }

  }

  if (supportedparametersstring != null) {

   try {

    this.supportedparameters = supportedparametersstring;

   } catch (NumberFormatException e) {

   }

  }

  if (astring != null) {

   try {

    this.a = Double.valueOf(astring).doubleValue();

    if (supportedparameters.indexOf("a")>=0) { this.ap = true; }

   } catch (NumberFormatException e) {

   }

  }

  if (bstring != null) {

   try {

    this.b = Double.valueOf(bstring).doubleValue();

    if (supportedparameters.indexOf("b")>=0) { this.bp = true; }

   } catch (NumberFormatException e) {

   }

  }

  if (cstring != null) {

   try {

    this.c = Double.valueOf(cstring).doubleValue();

    if (supportedparameters.indexOf("c")>=0) { this.cp = true; }

   } catch (NumberFormatException e) {

   }

  }

  if (dstring != null) {

   try {

    this.d = Double.valueOf(dstring).doubleValue();

    if (supportedparameters.indexOf("d")>=0) { this.dp = true; }

   } catch (NumberFormatException e) {

   }

  }

  if (estring != null) {

   try {

    this.e = Double.valueOf(estring).doubleValue();

    if (supportedparameters.indexOf("e")>=0) { this.ep = true; }

   } catch (NumberFormatException e) {

   }

  }

  if (fstring != null) {

   try {

    this.f = Double.valueOf(fstring).doubleValue();

    if (supportedparameters.indexOf("f")>=0) { this.fp = true; }

   } catch (NumberFormatException e) {

   }

  }

  if (hstring != null) {

   try {

    this.h = Double.valueOf(hstring).doubleValue();

    if (supportedparameters.indexOf("h")>=0) { this.hp = true; }

   } catch (NumberFormatException e) {

   }

  }

  if (kstring != null) {

   try {

    this.k = Double.valueOf(kstring).doubleValue();

    if (supportedparameters.indexOf("k")>=0) { this.kp = true; }

   } catch (NumberFormatException e) {

   }

  }

  if (mstring != null) {

   try {

    this.m = Double.valueOf(mstring).doubleValue();

    if (supportedparameters.indexOf("m")>=0) { this.mp = true; }

   } catch (NumberFormatException e) {

   }

  }

  if (nstring != null) {

   try {

    this.n = Double.valueOf(nstring).doubleValue();

    if (supportedparameters.indexOf("n")>=0) { this.np = true; }

   } catch (NumberFormatException e) {

   }

  }

  if (pstring != null) {

   try {

    this.p = Double.valueOf(pstring).doubleValue();

    if (supportedparameters.indexOf("p")>=0) { this.pp = true; }

   } catch (NumberFormatException e) {

   }

  }



  if (tdb) {

   if (ap || bp || cp || dp || ep || fp || hp || kp || mp || np || pp) {

    this.curve = new Curve(this.curvename, this.tmin, this.tmax, this.td, this.dt, this.xb, this.xt, this.yb, this.yt, this.a, this.b, this.c, this.d, this.e, this.f, this.h, this.k, this.m, this.n, this.p);

   } else {

    this.curve = new Curve(this.curvename, this.tmin, this.tmax, this.td);

   }

  } else {

   if (ap || bp || cp || dp || ep || fp || hp || kp || mp || np || pp) {

    this.curve = new Curve(this.curvename, this.tmin, this.tmax, this.numberofpoints, this.dt, this.xb, this.xt, this.yb, this.yt, this.a, this.b, this.c, this.d, this.e, this.f, this.h, this.k, this.m, this.n, this.p);

   } else {

    this.curve = new Curve(this.curvename, this.tmin, this.tmax, this.td);

   }

  }

  setLayout(new BorderLayout());

  this.curvepanel = new CurvePanel(this.curve, 0);

  this.curvepanel.setParameters(this.a, this.b, this.c, this.d, this.e, this.f, this.h, this.k, this.m, this.n, this.p);

  add("Center", this.curvepanel);

  this.curvecontrols = new CurveControls(this.curvepanel, this.ap, this.bp, this.cp, this.dp, this.ep, this.fp, this.hp, this.kp, this.mp, this.np, this.pp);

  add("South", this.curvecontrols);



 } /* end of initialisation method */



} /* end of FamousCurves applet */

