// Tyler Rigsby, CSE 142 // Draws a simple boxy car. // This version is complete with parameters for the x, y, and size of the car. import java.awt.*; public class DrawCar { public static void main(String[] args) { DrawingPanel panel = new DrawingPanel(500, 500); panel.setBackground(Color.LIGHT_GRAY); Graphics g = panel.getGraphics(); drawCar(g, 10, 30, 100); drawCar(g, 120, 120, 200); for (int i = 0; i < 10; i++) { drawCar(g, 100 * i, 300, 100 - i * 10); } } // Draws a car with the upper-left corner at the specified x, y // coordinate and the specified size. public static void drawCar(Graphics g, int x, int y, int size) { g.setColor(new Color(132, 240, 46)); g.fillRect(x, y, size, size / 2); g.setColor(Color.RED); g.fillOval(x + size / 10, y + 4 * size / 10, size / 5, size / 5); g.fillOval(x + 7 * size / 10, y + 4 * size / 10, size / 5, size / 5); g.setColor(Color.CYAN); g.fillRect(x + 7 * size / 10, y + size / 10, 3 * size / 10, 2 * size / 10); } }