import java.applet.*;
import java.awt.*;

public class BasicPicture extends Applet
{
  Graphics pen;
  protected Button b1;
  protected Color currentColor;
  protected int currentX;
  protected int currentY;
  protected int currentSize;
  protected int currentAngle;
  protected Info currentInfo;
  protected Graphics currentPen;
  static protected int seed = 0;
  
/*******************************************************************************/  
  
  public BasicPicture() {}

/*******************************************************************************/  

  public BasicPicture(Color c, int x, int y, int size, int angle, Graphics pen) {
	currentColor = c;
	currentX = x;
	currentY = y;
	currentSize = size;
	currentAngle = angle;
	currentPen = pen;
	currentInfo = new Info(x,y,size,angle,pen);
  }	 


/*******************************************************************************/  

  public void init()
  {
    currentColor = Color.black;
	currentX = 300;
	currentY = 300;
	currentSize = 300;
	currentAngle = 0;
	currentInfo = new Info(currentX,currentY,currentAngle,currentSize,this.getGraphics());
 }

  public void paint(Graphics graph)
  {
    // Draws the base case on the screen
	              			currentPen = this.getGraphics();
						      draw();
  }
  

/********************************************************************************
 * Does the Drawing		
 ********************************************************************************/ 
  public void draw() { 			
}



/********************************************************************************	
 ********************************************************************************/ 
  public void setFontSize(int newSize) {
	currentPen.setFont(new Font (currentPen.getFont().toString(), Font.PLAIN, newSize));
	}
	
/********************************************************************************
 * Does the rotation		
 ********************************************************************************/ 
  public int newX(int x1, int y1, int a){
  double x,y,ans, angle;

  x = (double) (x1 - currentX); 
  y = (double) (y1 - currentY);
  angle = ((double) a * 2.0 * java.lang.Math.PI /360.0) ;  // convert to radians
  ans = (x * java.lang.Math.cos(angle)) - (y * java.lang.Math.sin(angle));
  return((int) ans + currentX);
  }

/********************************************************************************
 * Does the rotation		
 ********************************************************************************/  
public int newY(int x1, int y1, int a){
  double x,y,ans, angle;

  x = (double) (x1 - currentX); 
  y = (double) (y1 - currentY);
  angle = ((double) a * 2.0 * java.lang.Math.PI /360.0) ;  // convert to radians
  ans = (x * java.lang.Math.sin(angle)) + (y * java.lang.Math.cos(angle));
  return((int) ans + currentY);
  }

/*******************************************************************************/  
  public void drawArc(Color c, int x1, int y1, int x2, int y2) {
  }

/*******************************************************************************
 * drawRectangle - draws a rectangle either filled or unfilled
/*******************************************************************************/  
  public void drawRectangle(Color c, int x1, int y1, int x2, int y2, boolean fill) {
    drawThing(c, x1, y1, x2, y1, y2 - y1, fill);  
  }

/*******************************************************************************
 * drawline - draws a line from point x1,y1 to x2,y2, thickness of thickness
 *******************************************************************************/
  public void drawLine(Color c, int x1, int y1, int x2, int y2, int thickness) {
	if (thickness < 2) 
		drawThing(c,x1,y1,x2,y2,thickness, true);
	else if (x1 != x2) // not a vertical line

		drawThing(c, x1, y1 - thickness/2, x2, y2-thickness/2, thickness, true);
    else // vertical line 
		drawThing(c, x1 - thickness/2, y1, x2 - thickness/2, y2, thickness, true);

		
		
  }

/*******************************************************************************
 * drawThing - Either draws a rectangle or a fat line depending on how you think
 * about it (A fat line is really a rectangle if you think about it)  You should
 * never have to call this directly, use drawRectangle and drawLine
 *******************************************************************************/
  protected void drawThing(Color c, int x1, int y1, int x2, int y2, int thickness, boolean fill) {
    int x[], y[];
    x = new int[5];
    y = new int[5];

	Color color = currentPen.getColor();
	currentPen.setColor(c);
	if (thickness == 1) currentPen.drawLine(newX(x1,y1,currentAngle),newY(x1,y1,currentAngle),
											newX(x2,y2,currentAngle), newY(x2,y2,currentAngle));
	else {
      if (x1 != x2) {
	  x[0] = newX(x1,y1,currentAngle); y[0] = newY(x1,y1,currentAngle);
	  x[1] = newX(x2,y2,currentAngle); y[1] = newY(x2,y2,currentAngle);
   	  x[2] = newX(x2, y2 + thickness - 1,currentAngle) ; y[2] = newY(x2, y2 + thickness - 1,currentAngle);
	  x[3] = newX(x1, y1 + thickness - 1,currentAngle) ; y[3] = newY(x1, y1 + thickness - 1,currentAngle);
	  x[4] = newX(x1,y1,currentAngle); y[4] = newY(x1,y1,currentAngle);

      } else {
	  x[0] = newX(x1,y1,currentAngle); y[0] = newY(x1,y1,currentAngle);
	  x[1] = newX(x1 + thickness - 1,y1,currentAngle); y[1] = newY(x1 + thickness - 1,y1,currentAngle);
	  x[2] = newX(x2 + thickness - 1, y2,currentAngle); y[2] = newY(x2 + thickness - 1, y2,currentAngle);
	  x[3] = newX(x2,y2,currentAngle); y[3] = newY(x2,y2,currentAngle);
	  x[4] = newX(x1,y1,currentAngle); y[4] = newY(x1,y1,currentAngle);

      }
//	 for (int i = 0; i <4;i++)
//		System.out.println("Point " + i + "(x,y) = (" + x[i] +","+y[i]+")");
    if (fill) currentPen.fillPolygon(x,y,4); 
	else currentPen.drawPolygon(x,y,5);
	}

	currentPen.setColor(color);

  }
/*******************************************************************************
 *******************************************************************************/  
  public void drawCircle(Color c, int x1, int y1, int radius, boolean fill) {
  Color color;
  color = currentPen.getColor();
  currentPen.setColor(c);
  int x = newX(x1-radius,y1-radius, currentAngle);
  int y = newY(x1-radius,y1-radius, currentAngle);

  if (fill) currentPen.fillOval( x, y  ,radius*2, radius*2);
	else
  currentPen.drawOval(x,y, radius*2, radius*2);

  currentPen.setColor(color);
  }



/*******************************************************************************
 *******************************************************************************/  
  public void drawText(Color c, int x1, int x2, int size, String text) {
  }

/*******************************************************************************
 * randomColor - returns a new random color gets it seed from the			   *
 *   clock so if it is called back to back real quick it will				   *
 *   return the same color													   *
 *******************************************************************************/  
  public Color randomColor() {
	int r,gr,b;
	java.util.Random ran;


	if (seed == 0)
	  ran = new java.util.Random();
	else
	  ran = new java.util.Random(seed);
	
	r = ran.nextInt() % 256;
	gr = ran.nextInt() % 256;
	b = ran.nextInt() % 256;
	seed = ran.nextInt();

	return((new Color(r,gr,b)));
  }

/*******************************************************************************
 nextColor - returns the next color in a cycle so you can cycle colors easily
 *******************************************************************************/  
 public Color nextColor(Color currentColor) {
	if (currentColor == Color.black) return(Color.blue);
	else if (currentColor == Color.blue) return(Color.cyan);
	else if (currentColor == Color.cyan) return(Color.gray);
	else if (currentColor == Color.gray) return(Color.green);
	else if (currentColor == Color.green) return(Color.magenta);
	else if (currentColor == Color.magenta) return(Color.orange);
	else if (currentColor == Color.orange) return(Color.pink);
	else if (currentColor == Color.pink) return(Color.red);
	else if (currentColor == Color.red) return(Color.yellow);
	return(Color.black);
  }


}

class Info {

	int x;
	int y;
	int angle;
	int size;
	Graphics g;

	Info() {}

	Info (int a, int b, int ang, int sz, Graphics gr) {
		x = a;
		y = b;
		angle = ang;
		size = sz;
		g = gr;
	}
}