import java.awt.Graphics;
import java.awt.Color;
import java.util.Random;

/**
 * A colored graph.
 *
 * @version 1.1    February 20, 2002
 * @author Franck van Breugel
 */
public class Graph
{
    private int nPoints;                  // number of points of this graph
    private int[] xPoints;                // x-coordinates of the points of this graph
    private int[] yPoints;                // y-coordinates of the points of this graph
    private Color color;                  // color of this graph

    private static final int MAX = 10;    // maximal number of points of this graph
    private static final int RGB = 255;   // maximal value to define the amount of red, green and blue in a color.

    /**
     * Creates a graph.  The number of points in the range 1...MAX.  The
     * y-coordinate of each point is in the range 0...HEIGHT.  The x-coordinates
     * are evenly distributed over 0...WIDTH.  The color is chosen randomly.
     *
     * @param WIDTH maximal x-coordinate.
     * @param HEIGHT maximal y-ccordinate.
     */
    public Graph(int WIDTH, int HEIGHT)
    {
        Random generator = new Random();
        nPoints = 1 + generator.nextInt(MAX);
        xPoints = new int[nPoints];
        yPoints = new int[nPoints];
        xPoints[0] = 0;
        yPoints[0] = generator.nextInt(HEIGHT);
        for (int i = 1; i < nPoints; i++)
	{
            xPoints[i] = i * (WIDTH / (nPoints - 1));
            yPoints[i] = generator.nextInt(HEIGHT);
	}
        color = new Color(generator.nextInt(RGB), generator.nextInt(RGB), generator.nextInt(RGB));
    }

    /** 
     * Draws this graph on the specified component.
     *
     * @param page component on which this graph is drawn.
     */
    public void draw(Graphics page)
    {
        page.setColor(color);
        page.drawPolyline(xPoints, yPoints, nPoints);
    }
}
