void MutateShape(Random rand, DNA dna, Shape shape, TaskState task)
{
shape.PreviousState = shape.Clone() as Shape;
int colorDelta = (byte)rand.Next(1, MaxColorDelta + 1) * (rand.Next(2) == 0 ? 1 : -1);
switch (rand.Next(10))
{
case 0:
shape.Color =
Color.FromArgb(
Math.Max(task.ProjectOptions.MinAlpha, Math.Min(255, shape.Color.A + colorDelta)),
shape.Color.R, shape.Color.G, shape.Color.B);
dna.LastMutation = MutationType.AdjustColor;
if (rand.Next(10) == 0)
{
MutateMultiplePoints(shape, rand, dna, task);
dna.LastMutation = MutationType.ReplaceShape;
}
break;
case 1:
shape.Color = Color.FromArgb(shape.Color.A,
Math.Max(0, Math.Min(255, shape.Color.R + colorDelta)),
shape.Color.G, shape.Color.B);
dna.LastMutation = MutationType.AdjustColor;
if (rand.Next(10) == 0)
{
MutateMultiplePoints(shape, rand, dna, task);
dna.LastMutation = MutationType.ReplaceShape;
}
break;
case 2:
shape.Color = Color.FromArgb(shape.Color.A, shape.Color.R,
Math.Max(0, Math.Min(255, shape.Color.G + colorDelta)),
shape.Color.B);
dna.LastMutation = MutationType.AdjustColor;
if (rand.Next(10) == 0)
{
MutateMultiplePoints(shape, rand, dna, task);
dna.LastMutation = MutationType.ReplaceShape;
}
break;
case 3:
shape.Color = Color.FromArgb(shape.Color.A, shape.Color.R, shape.Color.G,
Math.Max(0, Math.Min(255, shape.Color.B + colorDelta)));
dna.LastMutation = MutationType.AdjustColor;
if (rand.Next(10) == 0)
{
MutateMultiplePoints(shape, rand, dna, task);
dna.LastMutation = MutationType.ReplaceShape;
}
break;
default:
MutateMultiplePoints(shape, rand, dna, task);
break;
}
}