
import java.applet.*;
import java.awt.*;
import java.net.*;
import java.util.*;
import java.io.*;

public class Thales8 extends Applet implements Runnable {

	Thread design;
	Dimension d;
	int 	posx, posy, minix, miniy;
	int 	w, h, w2, h2;
	float 	tempx, tempy;

	Image offscreen;
	Dimension offscreensize;
	Graphics offgraphics;

	private Color bgd, fgd;
	int x[] = new int[14];
	int y[] = new int[14];		
	int ww[] = new int[14];		
	int hh[] = new int[14];

	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 init() {

		d = size();
		w2 = d.width;
		h2 = d.height;
		w = w2-2;
		h = h2-2;
		posx=w2/2; posy=h2/2;

		for(int i=0; i<14; i++) {
			x[i] = (int)((float)(i)*(float)w/28);
			y[i] = (int)((float)(i)*(float)h/28);		
			ww[i] = (int)((14-(float)i)*(float)w/14);
			hh[i] = (int)((14-(float)i)*(float)h/14);
		}

		bgd = Color.white;
		fgd = Color.black;

	} // init


	public void run() {
	} // run


	public void update(Graphics g) {
		this.paint(g);
	} // update

	public void setValues(int a, int b) {

		minix = Math.min(a,(w-a));
		miniy = Math.min(b,(h-b));

		if (minix==a) {
			tempx=((float)a/14);
			for(int i=0; i<14; i++) {
				x[i] = (int)((float)a-(14-(float)i)*tempx);
			}
		}

		if (minix==(w-a)) {
			tempx=(((float)w-(float)a)/14);
			for(int i=0; i<14; i++) {
				x[i] = (int)((float)a+(14-(float)i)*tempx-(float)ww[i]);
			}
		}

		if (miniy==b) {
			tempy=((float)b/14);
			for(int i=0; i<14; i++) {
				y[i] = (int)((float)b-(14-(float)i)*tempy);		
			}
		}

		if (miniy==(h-b)) {
			tempy=(((float)h-(float)b)/14);
			for(int i=0; i<14; i++) {
				y[i] = (int)((float)b+(14-(float)i)*tempy-(float)hh[i]);		
			}
		}


	}

	public void paint(Graphics g) {
		if ((offscreen == null) || (w2 != offscreensize.width) || 
			(h2 != offscreensize.height)) {

			offscreen = createImage(w2, h2);
			offscreensize = d;
			offgraphics = offscreen.getGraphics();
		}
	
		offgraphics.setColor(bgd);
		offgraphics.fillRect(0,0,w2,h2);
		offgraphics.setColor(fgd);

		offgraphics.drawOval(x[1],y[1],ww[1],hh[1]);
		for (int i=0; i<14; i++) {
			offgraphics.drawOval(x[i],y[i],ww[i],hh[i]);
		}
		g.drawImage(offscreen, 0, 0, null);
	
	} // paint

	public boolean mouseMove(Event e, int x, int y) {
		posx = x; posy = y;
		setValues(posx, posy);
		this.repaint();
		return true;
	}  //mouseDown

}

