// Helene Martin, CSE 142 // Draws cars of different sizes in different positions. // NOTE: // - we added x and y parameters first // - x and y parameters relate to translation so we use addition and subtraction // - size relates to scaling so we used multiplication and division // - we also had to scale the shift factors import java.awt.*; public class DrawCar { public static void main(String[] args) { DrawingPanel panel = new DrawingPanel(400, 100); panel.setBackground(Color.LIGHT_GRAY); Graphics brush = panel.getGraphics(); drawCar(brush, 10, 30, 100); drawCar(brush, 150, 10, 50); } // Draws a car. The car's width is size and its top left corner is x, y public static void drawCar(Graphics g, int x, int y, int size) { g.setColor(Color.BLACK); g.fillRect(x, y, size, size / 2); g.setColor(Color.RED); g.fillOval(x + size / 10, y + 2 * size / 5, size / 5, size / 5); g.fillOval(x + size * 7 / 10, y + size * 2 / 5, size / 5, size / 5); g.setColor(Color.CYAN); g.fillRect(x + size * 7 / 10, y + size / 10, 3 * size / 10, size / 5); } }