
import java.applet.*;
import java.awt.*;
import java.net.*;
import java.util.*;
import java.io.*;

public class Mom extends Applet implements Runnable {

	Dimension d;
	Thread design;
	int counter=0, maxi=0, mini=0;
	int posx3=-50, posy3=-50, posx1=-50, posy1=-50, posx2=-50, posy2=-50;
	int x1,y1,x2,x3,y2,y3, r=0, w=0, h=0;
	private Font font;
	private Color white, black;
	int a=0;
	Image offscreen;
	Dimension offscreensize;
	Graphics offgraphics;

	public String getAppletInfo() {
		return "Thales seriEs: carpetPoetry, by joey beRzowski";
      } // getAppletInfo

      public void start() {
		repaint();
		if (design == null) {
			design = new Thread(this);
			design.start();
		}
      } // start


      public void stop() {
		if ((design != null) && design.isAlive())
			design.stop();
		design = null;
      } // stop


      public void destroy() {
		if ((design != null) && design.isAlive())
			design.stop();
		design = null;
      } // destroy

	  public void run() {
		
      } // destroy


	public void init() {
	
		white =  Color.white;
		black =  Color.black;
		this.setBackground(white);

		d = size();
		w=d.width;
		h=d.height;
		offscreen = createImage(d.width, d.height);
		offscreensize = d;
		offgraphics = offscreen.getGraphics();

	} // init


	public void update(Graphics g) {
		paint(g);
	} // update

	public void paint(Graphics g) {

		
	//	offgraphics.drawLine(0,y1,w,y1);
	//	offgraphics.drawLine(x1,0,x1,h);
	//	width = Math.max((x3-x1), (y1-y3));
	//	font = new Font("Courier", Font.PLAIN, width);
	//	offgraphics.setFont(font);
	//	offgraphics.drawString("x", x1, y1);

		g.drawImage(offscreen, 0, 0, null);
  
	} // paint
	 

	public void squareLine(int xOne, int yOne, int xTwo, int yTwo, Graphics graph) {
	
		int xMax;
		int yMax;
		int xMin;
		int yMin;
			
		xMax = Math.max(xOne, xTwo);
		if (xMax == xOne) {yMax = yOne; xMin = xTwo;  yMin = yTwo;}
		else { yMax = yTwo; xMin = xOne; yMin = yOne;}

		int ww = (xMax-xMin)/15;
		int hh = (yMax-yMin)/15;

		int slope;

		if (ww!=0) slope = hh/ww;
		else slope = hh/(ww+1);

		for(int i=-45; i<=45; i++) {	
			graph.drawRect(i*ww+xMin+(int)(Math.random()*6), i*hh+yMin+(int)(Math.random()*6), (int)(Math.random()*7), (int)(Math.random()*7));					
		}

	}

	public boolean mouseDown(Event e, int x, int y) {
		
		if (a==0) {
			posx1 = x; posy1 = y;
			offgraphics.setColor(white);
			offgraphics.fillRect(0,0,d.width,d.height);
			repaint();
			a=1;
		}

		else {

			if (a==1) {
				posx2 = x; posy2 = y;
				a=2;
			}

			else  {
				if (a==2) {
					posx3 = x; posy3 = y;
					x1 = Math.min(Math.min(posx1,posx2),posx3);
					y1 = Math.min(Math.min(posy1,posy2),posy3);

					x3 = Math.max(Math.max(posx1,posx2),posx3);
					y3 = Math.max(Math.max(posy1,posy2),posy3);

					x2 = posx1+posx2+posx3-x1-x3;
					y2 = posy1+posy2+posy3-y1-y3;
					int circleWidth = x3-x1;
					int circleHeight = y3-y1;

					offgraphics.setColor(black);	
			//		offgraphics.fillOval(posx1-3,posy1-3,5,5);
			//		offgraphics.fillOval(posx2-3,posy2-3,5,5);
			//		offgraphics.fillOval(posx3-3,posy3-3,5,5);

			//		offgraphics.drawOval(posx1-150,posy1-150,300,300);
			//		offgraphics.drawOval(posx2-150,posy2-150,300,300);
			//		offgraphics.drawOval(posx3-150,posy3-150,300,300);

					squareLine(posx1,posy1,posx2,posy2,offgraphics);
					squareLine(posx3,posy3,posx2,posy2,offgraphics);
					squareLine(posx1,posy1,posx3,posy3,offgraphics);


					int xStep = circleWidth/10;
					int yStep = circleHeight/10;					

					repaint();
					a=0;
				}
			}
		}

		return true;
	}


}





