
//   STAR0.JAVA
//
//  by CS 120 Winter 2006  1pm class   JHorn instructor

import java.awt.*;

class Star1
	{
	private int points, radius, x, y;
	private boolean selected;

	public Star1(int newX, int newY,int inputPoints, int inputRadius)
		{
		x = newX;
		y = newY;
		points = inputPoints;
		radius = inputRadius;
		selected = false;

		}

	public void paint(Graphics g)
		{
		int almostHalf = points/2;
		double angle = almostHalf*2*Math.PI/points;
		Color original_color;
		original_color = g.getColor();
		if(selected)
		   g.setColor(Color.red);
		   else g.setColor(Color.blue);
		for (int p = 0; p < points; p++)
			{
			g.drawLine(x + (int)(radius * Math.sin(angle*p)),
				y - (int)(radius * Math.cos(angle*p)),
				x + (int)(radius * Math.sin(angle*(p+1))),
				y - (int)(radius * Math.cos(angle*(p+1))));
			}
	    g.setColor(original_color);
		}

	//  This is my simple "inside" method, which essentially uses
	//  a square, of side "radius", with center at x,y, as the
	//  "active area" considered to be "inside" the star.  This is
	//  conservative, since much of the square is not really
	//  inside the star.  See Barry and Larry's "inside" method
	//  below, for a "tighter" active area (a circle).
    public boolean inside_Jeff(int xp, int yp)
        {
           return ( x-radius <= xp &&  xp <= x+radius  &&
                 y-radius <= yp && yp <= y+radius );
         }

    //  This is the authors' "inside" method.  It effectively
    //  uses a circle of radius "radius" centered at the star's
    //  x,y coordinate.  Note that this is "tighter" than the
    //  square used in Jeff's "inside" above.
    public boolean inside(int xp, int yp)
        {
            if ( radius*radius > (x-xp)*(x-xp) + (y-yp)*(y-yp))
                 return true;
                 else return false;
        }

    public void select()
        {
			selected = true;
		}

    public void unselect()
        {
			selected = false;
		}

	public void toggle()
	    {
			selected = ! selected;
	   }

	public void bigger()
		{
		        if(selected)
		          radius += 1;
		}

	public void smaller()
		{
    	        if(selected && radius > 0)
    	           radius -=1;
		}

	public void more()
		{
		   if(selected)
		     points += 2;
		}

	public void fewer()
		{
			if(selected && points > 3)
			  points -= 2;
		}

    public void move(int new_x, int new_y)
      {
          x = new_x; y= new_y;
      }
	}















