import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.*;

/**
   A car shape that can be positioned anywhere on the screen.
*/
public class Car
{
   /**
      Constructs a car with a given top left corner
      @param x the x coordinate of the top left corner
      @param y the y coordinate of the top left corner
   */
   public Car(double x, double y)
   {
      xLeft = (int) x;
      yTop = (int) y;
      scale = Math.random()*3;
   }

   /**
      Draws the car
      @param g2 the graphics context
   */
   public void draw(Graphics2D g2)
   {
      Rectangle2D.Double body
         = new Rectangle2D.Double(xLeft, yTop + (int)(scale*10), (int)(scale*60), (int)(scale*10));
      Ellipse2D.Double frontTire
         = new Ellipse2D.Double(xLeft + (int)(scale*10), yTop + (int)(scale*20), (int)(scale*20), (int)(scale*20));
      Ellipse2D.Double rearTire
         = new Ellipse2D.Double(xLeft + (int)(scale*40), yTop + (int)(scale*20), (int)(scale*20), (int)(scale*20));

/*      // the bottom of the front windshield
      Point2D.Double r1
         = new Point2D.Double(xLeft + 10, yTop + 10);
      // the front of the roof
      Point2D.Double r2
         = new Point2D.Double(xLeft + 20, yTop);
      // the rear of the roof
      Point2D.Double r3
         = new Point2D.Double(xLeft + 40, yTop);
      // the bottom of the rear windshield
      Point2D.Double r4
         = new Point2D.Double(xLeft + 50, yTop + 10);

      Line2D.Double frontWindshield
         = new Line2D.Double(r1, r2);
      Line2D.Double roofTop
         = new Line2D.Double(r2, r3);
      Line2D.Double rearWindshield
         = new Line2D.Double(r3, r4);
 */
 	  int[] x = { (int)(scale*0)+xLeft, (int)(scale*30)+xLeft, (int)(scale*30)+xLeft, (int)(scale*10)+xLeft};
 	  int[] y = {(int)(scale*10)+yTop , (int)(scale*10)+yTop ,  0+yTop ,  0+yTop };

 	  Polygon cab = new Polygon(x, y, x.length);

 	  g2.setColor(new Color((int)(Math.random()*256),
 	  						(int)(Math.random()*256),
 	  						(int)(Math.random()*256)));
 	  g2.fill(cab);
 	  g2.fill(body);

 	  g2.setColor(Color.black);

 	  g2.draw(cab);
      g2.draw(body);
      g2.fill(frontTire);
      g2.fill(rearTire);
 /*   g2.draw(frontWindshield);
      g2.draw(roofTop);
      g2.draw(rearWindshield);
 */
   }

   private int xLeft;
   private int yTop;
   private double scale;
}
