package shears;

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

import psplot.*;
import real.*;


class Shear4Canvas extends ShearCanvas {

	public Shear4Canvas(Applet e, int w, int h,
		double B, double H, double S) {
		super(e, w, h, B, H, S);
		mkFixedPaths();
	}
	
	PlotPath rectangle;
	PlotPath top;
	PlotPath bottom;
	
	PlotPath leftTriangle;
	PlotPath rightTriangle;
	PlotPath smallTriangle;
	
	void mkFixedPaths() {
		rectangle = new PlotPath(this);
		top = new PlotPath(this);
		bottom = new PlotPath(this);
		
		rectangle.moveto(0,0);
		rectangle.lineto(0,ht);
		rectangle.lineto(b,ht);
		rectangle.lineto(b,0);
		rectangle.close();
		
		top.moveto(-4.5,ht);
		top.lineto(6.5,ht);

		bottom.moveto(-4.5,0);
		bottom.lineto(6.5,0);
	}

	public void draw() {
		ready = false;
		top.stroke(Color.black);
		bottom.stroke(Color.black);
		
		rectangle.fill(Color.cyan);
		rectangle.stroke(Color.black);
		
		PlotPath parallelogram = new PlotPath(this);
		parallelogram.moveto(0,0);
		parallelogram.lineto(b,0);
		parallelogram.lineto(b+s,ht);
		parallelogram.lineto(s,ht);
		parallelogram.close();
		
		parallelogram.fill(Color.blue);
		parallelogram.stroke(Color.black);
		
		if (s > 0) {
			leftTriangle = new PlotPath(this);
			leftTriangle.moveto(0, 0);
			leftTriangle.lineto(0, ht);
			leftTriangle.lineto(s, ht);
			leftTriangle.close();
			leftTriangle.fill(Color.cyan);
			
			rightTriangle = new PlotPath(this);
			rightTriangle.moveto(b, 0);
			rightTriangle.lineto(b, ht);
			rightTriangle.lineto(b+s, ht);
			rightTriangle.close();
			rightTriangle.fill(Color.blue);
			
			rightTriangle.stroke(Color.black);
			leftTriangle.stroke(Color.black);
			if (s > b) {
				smallTriangle = new PlotPath(this);
				smallTriangle.moveto(b, ht - (ht/s)*(s-b));
				smallTriangle.lineto(b, ht);
				smallTriangle.lineto(s, ht);
				smallTriangle.close();
				smallTriangle.fill(Color.magenta);
				smallTriangle.stroke(Color.black);
			}
			
		} else {
			PlotPath ell = new PlotPath(this);
			ell.moveto(0, 0);
			ell.lineto(0, ht);
			ell.stroke(Color.black);
			if (s < -b) {
				smallTriangle = new PlotPath(this);
				smallTriangle.moveto(0, ht);
				smallTriangle.lineto(b+s, ht);
				smallTriangle.lineto(0, ht - (b+s)*ht/s);
				smallTriangle.close();
				smallTriangle.fill(Color.magenta);
				smallTriangle.stroke(Color.black);
			}
		}
		cn.draw();
		ready = true;
	}
}



// ------------------------------------------------------

public class Shear4Applet extends ShearApplet {
	
	public void init() {
		setLayout(new BorderLayout(0, 0));
		setBackground(Color.white);
		pic = new Shear4Canvas(this, bounds().width, bounds().height,
			b, h, s);
		add(pic);
		show();
	}
}
