import jan.*; import java.awt.*; class SuperPlotter { SuperPlotter(Biotope b) { b.setAlignment(b.right); b.goFromTo(-100,0,100,0); b.dropArrow(); b.goFromTo(0,100,0,-100); b.dropArrow(); } public void draw (Biotope b) { int xPixel,yPixel; double x,y; b.setColor(b.tail, b.transparent); b.goTo(-100,0); for (xPixel=-100;xPixel<=100;xPixel++) { x=xPixel; y=f(x); y=scale(y); yPixel=(int)(-y); b.goTo(xPixel,yPixel); b.setColor(b.tail, Color.red);} } public double f (double x) { return 0.0;} public double scale (double y) { return 0.0;} } class CubePlotter extends SuperPlotter { CubePlotter(Biotope b) { super(b); } public double f (double x) { return x*x*x; } public double scale (double y) { return y/10000.0 ; } } class SinePlotter extends SuperPlotter { SinePlotter(Biotope b) { super(b); } public double f (double x) { x=Math.PI+x/Math.PI; return Math.sin(x); } public double scale (double y) { return y*100.0; } } class TanPlotter extends SuperPlotter { TanPlotter(Biotope b) { super(b); } public double f (double x) { x=x*Math.PI/201; // go close to PI/2 return Math.tan(x); } public double scale (double y) { return y/1.28; // 128=tan(PI/2.01) } } class ExpPlotter extends SuperPlotter { ExpPlotter(Biotope b) { super(b); } public double f (double x) { x=x*0.046; return Math.exp(x); } public double scale (double y) { return y; // } } public class A3P1 extends Biotope implements Executable { String func; CubePlotter c; SinePlotter s; TanPlotter t; ExpPlotter e; public static void main (String arguments []) {main ("A3P1", "mode=input,draw");} public void initialize () { addDataLine ("c"); message("c - cube"); message("s - sine"); message("t - tan"); message("e - exp"); } public void execute () { func=readString(1); initGecko(); c=new CubePlotter(this); s=new SinePlotter(this); t=new TanPlotter(this); e=new ExpPlotter(this); switch (func.charAt(0)) { case 'c' : c.draw(this); break; case 's' : s.draw(this); break; case 't' : t.draw(this); break; case 'e' : e.draw(this); break; default : message("Wrong letter"); } } }