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

/**
 * A colored circle has a center, a radius and a color.
 *
 * @version 1.1    February 1, 2002
 * @author Franck van Breugel
 * @see Point
 */
public class ColoredCircle
{
    private Point center;  // center of this circle
    private int radius;    // radius of this circle
    private Color color;   // color of this circle

    /*  
     * maximal value to define the amount of red, green and blue
     * in a color.
     */
    private static final int RGB = 255;

    /**
     * Creates a colored circle with the specified center, radius and
     * color.
     * 
     * @param center center of the colored circle.
     * @param radius radius of the colored circle.
     * @param color color of the colored circle.
     */
    public ColoredCircle(Point center, int radius, Color color)
    {
        this.center = center;
	this.radius = radius;
	this.color = color;
    }


    /**
     * Creates a colored circle.  The x-coordinate of its center is 
     * greater than or equal to 0 and smaller than the x-coordinate of
     * the specified point.  The y-coordinate of its center is
     * greater than or equal to 0 and smaller than the y-coordinate of
     * the specified point.  
     *
     * @param corner point that bounds the x- and y-coordinate of the 
     * center of the circle.
     */
    public ColoredCircle(Point corner)
    {
        int x = corner.getX();
        int y = corner.getY();

        Random generator = new Random();

        center = new Point(generator.nextInt(x), generator.nextInt(y));
        radius = generator.nextInt(Math.min(x, y) / 2);
        color = new Color(generator.nextInt(RGB), generator.nextInt(RGB), generator.nextInt(RGB));
    }

    /**
     * Tests if the specified point is within this colored circle.
     *
     * @param point to be checked.
     * @return true if the the specified point is within this colored,
     * circle, false otherwise.
     */
    public boolean contains(Point point)
    {
        return (point.distanceTo(center) < radius);
    }

    /**
     * Draws this colored circle on the specified component.
     *
     * @param page the component on which this circle is drawn.
     */
    public void draw(Graphics page)
    {
        page.setColor(color);
        int x = center.getX();
        int y = center.getY();        
	page.drawOval(x - radius, y + radius, 2 * radius, 2 * radius);
	page.fillOval(x - radius, y + radius, 2 * radius, 2 * radius);
    }

    /**
     * Returns a string representation of this colored circle.
     *
     * @return a string representation of this colored circle.
     */
    public String toString()
    {
        return "center: " + center.toString() + "\n" +
               "radius: " + radius + "\n" +
	       "color: " + color.toString();
    }
}
