package fr.upemlv.ir2.dessin;

import java.awt.Shape;
import java.awt.geom.Path2D;
import java.util.Random;

public class ShapeUtils {
	public static Shape createRandomStar(int width,int height){
		int min = Math.min(width,height);
		Random random = new Random();
		Path2D.Double shape = new Path2D.Double();
		int branches = random.nextInt(10)+5;
		int centerx=width/3+random.nextInt(width/3);
		int centery=height/3+random.nextInt(height/3);
		int radius1=random.nextInt(min/6)+min/6;
		int radius2=radius1/2;
		shape.moveTo(centerx+radius1,centery);
		double dPi=2*Math.PI;
		for(int i=1;i<branches;i++) {
			double theta = dPi*(i-.5)/branches;
			shape.lineTo(centerx+radius2*Math.cos(theta), centery+radius2*Math.sin(theta));
			theta = dPi*i/branches;
			shape.lineTo(centerx+radius1*Math.cos(theta), centery+radius1*Math.sin(theta));
		}
		double theta = dPi*(-.5)/branches;
		shape.lineTo(centerx+radius2*Math.cos(theta), centery+radius2*Math.sin(theta));
		shape.closePath();
		return shape;

	}
}
