// Earl Bergquist, Garfield High School
// 10/17/2010
// Parameterizing Graphics Methods

import java.awt.*;  // to use Graphics, Color

public class GraphicsParameters {
	public static void main(String[] args) {
		DrawingPanel panel = new DrawingPanel(300, 200);
		
		// Set its Background
		panel.setBackground(Color.LIGHT_GRAY);
		
		// Create the Graphics Object
		Graphics g = panel.getGraphics();
		
		// Using Methods, we can pass Graphics object g along...		
		//drawSingleCar(g);
			
		// Methods with Loops & Parameters...
		//stairs0(g);
		//stairs1(g);
		//stairs2(g);
		
		// Cars at Different Positions
		//drawXYCar(g, 10, 30);
		//drawXYCar(g, 150, 10);
		
		// Multiple Cars...
		//drawCar(g, 10, 30, 100);
		//drawCar(g, 150, 10, 50);
		//drawCars(g, 10, 130, 40, 5); 
				
	}
	
	
	// Draws a face with a rectangular mouth
	// Notice that drawn shapes "stack" (the last drawn is what shows up)
	public static void drawFace(Graphics g) {
		g.setColor(Color.ORANGE);
		g.fillOval(50, 50, 100, 100);
		
		g.setColor(Color.BLACK);
		g.fillOval(75, 80, 5, 20);
		g.fillOval(125, 80, 5, 20);
		
		g.setColor(Color.RED);
		g.drawRect(80, 120, 40, 10);	
	}
	
	// Draw ten stacked rectangles starting at (20, 20), height 10, 
	//   width starting at 100 and decreasing by 10 each time
	public static void stairs0(Graphics g) {
		for (int i = 0; i < 10; i++) {
    		g.drawRect(20, 20 + 10 * i, 100 - 10 * i, 10);
		}
	}
	
	// Both the width of the stairs and their starting position change
	// as we go down
	public static void stairs1(Graphics g) {
		for (int i = 0; i < 10; i++) {
    		g.drawRect(20 + 10 * i, 20 + 10 * i, 100 - 10 * i, 10);
		}
	}
	
	// The width of the stairs increases, the starting position decreases 
	public static void stairs2(Graphics g) {
		for (int i = 0; i < 10; i++) {
    		g.drawRect(110 - (10 * i), 20 + 10 * i, 10 + 10 * i, 10);
		}
	}
	
	// Standard Single Car
	public static void drawSingleCar(Graphics g) {	
		g.setColor(Color.BLACK);
		g.fillRect(10, 30, 100, 50);	
		
		g.setColor(Color.RED);	
		g.fillOval(20, 70, 20, 20);	
		g.fillOval(80, 70, 20, 20);
			
		g.setColor(Color.CYAN);	
		g.fillRect(80, 40, 30, 20);
	}
	
	// parameterized car method to location x, y
	public static void drawXYCar(Graphics g, int x, int y) {	
		g.setColor(Color.BLACK);
		g.fillRect(x, y, 100, 50);	
		
		g.setColor(Color.RED);	
		g.fillOval(x + 10, y + 40, 20, 20);	
		g.fillOval(x + 70, y + 40, 20, 20);
			
		g.setColor(Color.CYAN);	
		g.fillRect(x + 70, y + 10, 30, 20);
	}	
	
	// parameterized car method to location x, y scaled by size 
	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 + size * 2 / 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, size * 3 / 10, size / 5);
    }
	 
	 // Use drawCar to create a fleet of cars
	 public static void drawCars(Graphics g, int x, int y, int size, int count) {
	 	for(int i = 0; i < count; i++) {
			drawCar(g, x + i * 50, y, size);
		}
	 }
}		

