// Helene Martin, CSE 142 // Draws cars of different sizes in different positions. // goal: share a process for parameterizing a graphics-based method import java.awt.*; import java.awt.*; public class DrawCar { public static void main(String[] args) { DrawingPanel panel = new DrawingPanel(400, 300); panel.setBackground(Color.LIGHT_GRAY); Graphics gert = panel.getGraphics(); drawCar(gert, 10, 30, 100); drawCar(gert, 150, 10, 50); } // draws a car of width size with top left corner x, y public static void drawCar(Graphics g, int x, int y, int size) { // note: x and y parameters are easier to add first, Only relate to translation. // size parameter is harder. Deals with scaling but translation also needs // to be scaled. g.setColor(Color.BLACK); 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 + size * 7 / 10, y + size * 4 / 10, size / 5, size /5); g.setColor(Color.CYAN); g.fillRect(x + size * 7 / 10, y + size / 10, size * 3 / 10, size / 5); } }