package pythagoras;

import java.applet.*;
import java.awt.*;

import psplot.*;
import real.*;

class Euclid0 extends EuclidCanvas {
	
	public Euclid0(Applet e, int w, int h,
			double A, double B) {
		super(e, w, h, A, B);
		name = "0";
	}
	
	PlotPath triangle;
	PlotPath asquare;
	PlotPath bsquare;
	PlotPath csquare;
	
	void mkFixedPaths() {
		triangle = new PlotPath(this);
		asquare = new PlotPath(this);
		bsquare = new PlotPath(this);
		csquare = new PlotPath(this);
		
		triangle.moveto(0.0, 0.0);
		triangle.lineto(c, 0.0);
		triangle.lineto(x, y);
		triangle.close();
		
		asquare.moveto(0,0);
		asquare.lineto(x,y);
		asquare.lineto(x-y,x+y);
		asquare.lineto(-y,x);
		asquare.close();

		bsquare.moveto(x,y);
		bsquare.lineto(c,0);
		bsquare.lineto(c+x1,y1);
		bsquare.lineto(x+x1,y+y1);
		bsquare.close();

		csquare.moveto(0,0);
		csquare.lineto(c,0);
		csquare.lineto(c,-c);
		csquare.lineto(0,-c);
		csquare.close();

	}
	
	boolean ready = true;

	public void draw() {
		ready = false;
		triangle.fill(Color.cyan);
		triangle.stroke(Color.black);
		asquare.stroke();
		bsquare.stroke();
		csquare.stroke();
		
		PlotPath drop;
		double s;
		if (t < 1.0/5.0) {
			s = 5.0*t;
			drop = new PlotPath(this);
			drop.moveto(x, y);
			drop.lineto(x, interp(s, y, -c));
			drop.stroke(Color.black);
		} else if (t < 2.0/5.0) {
			drop = new PlotPath(this);
			drop.moveto(x, y);
			drop.lineto(x, -c);
			drop.stroke(Color.black);
			
			s = (t - 1.0/5.0)*5.0;
			drop = new PlotPath(this);
			drop.moveto(x, y);
			drop.lineto(interp(s, x, 0), interp(s, y, -c));
			drop.stroke(Color.black);
		} else if (t < 3.0/5.0) {
			drop = new PlotPath(this);
			drop.moveto(x, y);
			drop.lineto(x, -c);
			drop.stroke(Color.black);
			
			drop = new PlotPath(this);
			drop.moveto(x, y);
			drop.lineto(0, -c);
			drop.stroke(Color.black);
			
			s = (t - 2.0/5.0)*5.0;
			drop = new PlotPath(this);
			drop.moveto(-y, x);
			drop.lineto(interp(s, -y, c), interp(s, x, -0));
			drop.stroke(Color.black);
		
		} else if (t < 4.0/5.0) {
			drop = new PlotPath(this);
			drop.moveto(x, y);
			drop.lineto(x, -c);
			drop.stroke(Color.black);
			
			drop = new PlotPath(this);
			drop.moveto(x, y);
			drop.lineto(0, -c);
			drop.stroke(Color.black);
			
			drop = new PlotPath(this);
			drop.moveto(-y, x);
			drop.lineto(c, 0);
			drop.stroke(Color.black);
		
			s = (t - 3.0/5.0)*5.0;
			drop = new PlotPath(this);
			drop.moveto(x, y);
			drop.lineto(interp(s, x, c), interp(s, y, -c));
			// drop.lineto(c, -c);
			drop.stroke(Color.black);
		
		} else if (t < 1.0) {
			drop = new PlotPath(this);
			drop.moveto(x, y);
			drop.lineto(x, -c);
			drop.stroke(Color.black);
			
			drop = new PlotPath(this);
			drop.moveto(x, y);
			drop.lineto(0, -c);
			drop.stroke(Color.black);
			
			drop = new PlotPath(this);
			drop.moveto(-y, x);
			drop.lineto(c, 0);
			drop.stroke(Color.black);
		
			drop = new PlotPath(this);
			drop.moveto(x, y);
			drop.lineto(c, -c);
			drop.stroke(Color.black);
			
			s = (t - 4.0/5.0)*5.0;
			drop = new PlotPath(this);
			drop.moveto(c+x1, y1);
			drop.lineto(interp(s, c+x1, 0), interp(s, y1, 0));
			// drop.lineto(0, 0);
			drop.stroke(Color.black);
			
		} else {
			drop = new PlotPath(this);
			drop.moveto(x, y);
			drop.lineto(x, -c);
			drop.stroke(Color.black);
			
			drop = new PlotPath(this);
			drop.moveto(x, y);
			drop.lineto(0, -c);
			drop.stroke(Color.black);
			
			drop = new PlotPath(this);
			drop.moveto(-y, x);
			drop.lineto(c, 0);
			drop.stroke(Color.black);
		
			drop = new PlotPath(this);
			drop.moveto(x, y);
			drop.lineto(c, -c);
			drop.stroke(Color.black);
			
			drop = new PlotPath(this);
			drop.moveto(c+x1, y1);
			drop.lineto(0, 0);
			drop.stroke(Color.black);
		}
		ready = true;	
	}
	
}

