// *********************************************************************
// Grass.java
// This object creates a grassy knoll from randomized parameters.
//
// Murphy Stein
// NYU Computer Graphics
// 2006
// *********************************************************************

import java.awt.*;

public class Grass {

	static int NUM_BLADES = 10000;
	int x, y;
	static Color LIGHT_GREEN = new Color(0, 100, 10);
	static Color DARK_GREEN = new Color(0, 200, 10);
	
	Point PointArray[];
	Color ColorArray[];
	
	// ** Constructor **
	// Create a grass patch with NUM_BLADES starting from x, y
	// Patch dimensions are roughly 500x200 (WxH).  Blade positions
	// as well as color are randomly picked and then saved.
	public Grass (int x, int y)
	{
		int px, py;		
		this.x = x;
		this.y = y;
		
		PointArray = new Point[NUM_BLADES];
		ColorArray = new Color[NUM_BLADES];
		
		for (int i = 0; i < NUM_BLADES; i++) {
			ColorArray[i] = new Color(0, (int)(100 + Math.random()*10), 10);
			px = (int) ((double)x + (Math.random()*500));
			py = (int) ((double)y + (Math.random()*200));
			PointArray[i] = new Point(px,py);
		}

	}

	// draw some grass to the specified Graphics context
	public void draw(Graphics g) {
		int px, py;
		
		for (int i = 0; i < NUM_BLADES; i++) {
			px = (int)PointArray[i].getX();
			py = (int)PointArray[i].getY();
			if (py > (this.y + 10)) {
				g.setColor(ColorArray[i].darker());
				g.fillOval(px-5,py-5,10,10);
			}
			g.setColor(ColorArray[i]);
			g.drawLine(px,py,px,(int)(py+Math.random()*4 + 2));
		}
	}
}
