package pythagoras;

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

import psplot.*;
import real.*;

class Euclid3 extends EuclidCanvas {
	
	public Euclid3(Applet e, int w, int h,
		double A, double B) {
		super(e, w, h, A, B);
		name = "3";
	}
	
	PlotPath triangle;
	PlotPath rectangle;
	PlotPath asquare;
	PlotPath bsquare;
	PlotPath csquare;
	
	void mkFixedPaths() {
		triangle = new PlotPath(this);
		rectangle = 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();
		
		rectangle.moveto(0, 0);
		rectangle.lineto(0, -c);
		rectangle.lineto(x, -c);
		rectangle.lineto(x, 0);
		rectangle.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);
		
		PlotPath triangle0 = new PlotPath(this);
		triangle0.moveto(0, 0);
		triangle0.lineto(x, y);
		triangle0.lineto(-y, x);
		triangle0.close();
		triangle0.fill(Color.red);
		triangle0.stroke(Color.black);
		
		RealPoint P = new RealPoint(x, y);
		RealPoint Q = new RealPoint(x, 0);
		
		PlotPath triangle1 = new PlotPath(this);
		triangle1.moveto(0, 0);
		triangle1.lineto(P.interp(t, Q));
		triangle1.lineto(0, -c);
		triangle1.close();
		if (t < 1.0) {
			triangle1.fill(Color.red);
			triangle1.stroke(Color.black);
		} else {
			asquare.fill(Color.pink);
			asquare.stroke(Color.black);
			triangle0.fill(Color.red);
			triangle0.stroke(Color.black);
			rectangle.fill(Color.pink);
			rectangle.stroke(Color.black);
			triangle1.fill(Color.red);
			triangle1.stroke(Color.black);
		}
		ready = false;

	}
	
}

