I'm trying to generate a random irregular java.awt.Shape blob, something like the examples in the second answer (the one by Paul Gaborit) to this question on tex.stackexchange.com.
If there is a way to start with an Ellipse2D and then modify that similar to how it is done in TeX in that answer, great.
Otherwise, maybe I could do something like this?:
public Shape createShape(int pointCount, double max_variance, int median_radius,
int[] center)
{
int[][] pathPoints = new int[pointCount][2];
Random rand = new Random();
for (int i=0;i<pointCount;i++)
{
double angle = (2*Math.PI/((double)pointCount))*((double)i);
double temp_variance = (0.5-rand.nextDouble())*2.0*max_variance;
double temp_radius = mean_radius+temp_variance;
int x = Math.round(temp_radius*Math.cos(angle));
int y = Math.round(temp_radius*Math.sin(angle));
pathPoints[i] = new int[] {x+center[0],y+center[1]};
}
// somehow make pathPoints into a Shape with smooth curves
return shape;
}
Aucun commentaire:
Enregistrer un commentaire