package pythagoras;

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

import psplot.*;
import real.*;

class Euclid1 extends EuclidCanvas {
	
	public Euclid1(Applet e, int w, int h,
		double A, double B) {
		super(e, w, h, A, B);
		name = "1";
	}
	
	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 = new PlotPath(this);
		drop.moveto(x, y);
		drop.lineto(x, -c);
		drop.stroke(Color.black);
		
		double theta = 0.5*Math.PI;
		RealPoint P = new RealPoint(0, -c);
		RealPoint Q = new RealPoint(x, y);
		
		if (t < 1.0) {
			PlotPath triangle1 = new PlotPath(this);
			triangle1.moveto(0, 0);
			triangle1.lineto(c, 0);
			triangle1.lineto(-y, x);
			triangle1.close();
			triangle1.fill(Color.pink);
			triangle1.stroke(Color.black);

			PlotPath triangle0 = new PlotPath(this);
			triangle0.moveto(0, 0);
			triangle0.lineto(0, -c);
			triangle0.lineto(x, y);
			triangle0.close();
			triangle0.fill(Color.pink);
			triangle0.stroke(Color.black);

			triangle0 = new PlotPath(this);
			triangle0.moveto(0, 0);
			triangle0.lineto(P.rotated(t*theta));
			triangle0.lineto(Q.rotated(t*theta));
			triangle0.close();
			triangle0.fill(Color.red);
			triangle0.stroke(Color.black);
		} else {
			PlotPath triangle0 = new PlotPath(this);
			triangle0.moveto(0, 0);
			triangle0.lineto(0, -c);
			triangle0.lineto(x, y);
			triangle0.close();
			triangle0.fill(Color.pink);
			triangle0.stroke(Color.black);

			PlotPath triangle1 = new PlotPath(this);
			triangle1.moveto(0, 0);
			triangle1.lineto(c, 0);
			triangle1.lineto(-y, x);
			triangle1.close();
			triangle1.fill(Color.red);
			triangle1.stroke(Color.black);

		}
		ready = true;
	}
	
}

