RandomPoint.java 1.86 KB
import java.awt.Color;
/**
 * RandomPoint class is similar to a point with a color. It stores points, 
 * it is used for the random drawing method.
 **/
 public class RandomPoint
{
	private Color c;
	private int x,y,width,height;
	
	/** Creates a default RandomPoint. **/
	public RandomPoint(){}
	
	/** Creates a RandomPoint and takes in the screen sizes width and height. **/
	public RandomPoint(int width, int height)
	{
		// takes in variables and then randomly generates a starting x 
		// and y location
		this.width = width;
		this.height = height;
		x = (int)(Math.random()*width);
		y = (int)(Math.random()*height);
	}
	
	/** Figures out the next x location. **/
	public int nextX()
	{
		// checks if its a negative of a positive number then generates a random
		// point up to 50 places away, if its out of bounds then it returns to
		// the bounds
		int sign = (int)(Math.random()*2);
		if(sign == 0)
			x = x + (int)(Math.random()*50+1);
		else
			x = x - (int)(Math.random()*50+1);
		
		if(x < 0)
			x = 0;
		if(x > width)
			x = width;
			
		return x;
	}
	
	/** Figures out the next y location. **/
	public int nextY()
	{
		// checks if its a negative of a positive number then generates a random
		// point up to 50 places away, if its out of bounds then it returns to
		// the bounds
		int sign = (int)(Math.random()*2);
		if(sign == 0)
			y = y + (int)(Math.random()*200+1);
		else
			y = y - (int)(Math.random()*200+1);
		
		if(y < 0)
			y = 0;
		if(y > height)
			y = height;
			
		return y;
	}
	
	/** This method returns a random color. **/
	public Color getColor()
	{
		return new Color((int)(Math.random()*256),(int)(Math.random()*256),(int)(Math.random()*256));
	}
	
	/** This method returns the x value. **/
	public int getX(){return x;}
	/** This method returns the y value. **/
	public int getY(){return y;}
}