import java.awt.*;
import java.util.*;

public class vectors7 extends java.applet.Applet {
  int count=-1;
  String esempio;

  Punto pa =new Punto(60, 100);
  Punto pb =new Punto(240, 150);
  Punto pc =new Punto(45, 180);
  Punto p =new Punto(150, 70);

  Image imoffg, imoffg2;
  Graphics offg, offg2;
  
  public void init() {
    Dimension d = size();
    imoffg=createImage(d.width, d.height);
    offg=imoffg.getGraphics();
  }

  public void paint(Graphics g) {
	esempio = getParameter("esempio");
		
	Dimension d = size();
	offg.setColor(Color.white);
	offg.fillRect(0, 0, d.width, d.height);
    
    if (esempio.equals("es8")) {
      Linea L1 = new Linea(pa, pb);
      Linea L2 = new Linea(pc, p);
      Punto Pi= new Punto(L1, L2);

      (new Circonferenza(L1, L2, 20, false, false)).disegna(Color.red, offg);
      (new Circonferenza(L1, L2, 20, false, true)).disegna(Color.magenta, offg);
      (new Circonferenza(L1, L2, 20, true, false)).disegna(Color.blue, offg);
      (new Circonferenza(L1, L2, 20, true, true)).disegna(Color.cyan, offg);
      
      L1.disegna(Color.black, offg);
      L2.disegna(Color.black, offg);
 /*
      L1.ruota(new Punto(L1, L2), Math.PI/2);
      L2.ruota(new Punto(L1, L2), Math.PI/2);
      L1.disegna(Color.blue, offg);
      L2.disegna(Color.blue, offg);
  */
    
      offg.setColor(Color.black);
      offg.drawString("cliccare 4 punti che saranno estrmi di 2 linee", 10, 15);
      offg.drawString("e saranno calcolate le 4 circonferenze tangenti", 10, 27);
      offg.drawString("possibili cosiderando anche i loro prolungamenti", 10, 39);
      offg.drawString("all'infinito. Il raggio è fisso a 20", 10, 51);
      offg.drawString("L1", (int) L1.P1.x, (int) L1.P1.y);
      offg.drawString("L2",  (int) L2.P1.x, (int) L2.P1.y);
      offg.drawString("Pi",  (int) Pi.x, (int) Pi.y);
      
  
  
      g.drawImage(imoffg, 0, 0, null);
    }
  }
  
  public void update(Graphics g) {
    paint(g);
  }

/*
  public boolean mouseDrag(Event e, int x, int y) {
    if (esempio.equals("es4")) {
      p.x = x;
      p.y = y;
      repaint();
    }
   	
    if (esempio.equals("es5")) {
      p.x = x;
	    p.y = y;
      repaint();
    }
	  return false;
  }

  public boolean mouseMove(Event e, int x, int y) {
    if (esempio.equals("es6")) {
      p.x = x;
	    p.y = y;
      repaint();
    }

	  return false;
  }
*/

	public boolean mouseDown(Event e, int x, int y) {
    if (esempio.equals("es8")) {
	  count++;
	  count = count % 4;
      if (count==0) {
	      pa.x = x;
	      pa.y = y;
      }
	    if (count==1) {
	      pb.x = x;
	      pb.y = y;
      }
      if (count==2) {
	      pc.x = x;
	      pc.y = y;
      }
 	    if (count==3) {
	      p.x = x;
	      p.y = y;
        repaint();
      }

    }
	  return false;
  }

}