public DNA Initialize(Random rand, TaskState task)
{
var dna = new DNA {
Shapes = new Shape[task.Shapes]
};
for (int s = 0; s < task.Shapes; s++)
{
var shape = new Shape {
Color = Color.FromArgb(StartingAlpha, Color.R, Color.G, Color.B),
Points = new PointF[task.Vertices]
};
int maxRadius = (int)Math.Round(Math.Min(task.ImageWidth, task.ImageHeight) * MaxRadiusRatio);
int radius = rand.Next(MinRadius, maxRadius);
var center = new Point(rand.Next(radius - MaxOverlap, task.ImageWidth - radius + MaxOverlap),
rand.Next(radius - MaxOverlap, task.ImageHeight - radius + MaxOverlap));
for (int v = 0; v < task.Vertices; v++)
{
double t = v * Math.PI * 2 * Revolutions / task.Vertices + Angle * Math.PI * 2 + Math.PI / task.Vertices;
shape.Points[v].X = (float)(center.X + Math.Cos(t) * radius);
shape.Points[v].Y = (float)(center.Y + Math.Sin(t) * radius);
}
if (shape.GetBoundaries().Width < 1 || shape.GetBoundaries().Height < 1)
{
continue;
}
dna.Shapes[s] = shape;
}
return(dna);
}