//Mutating shape by changing number of points or changing their position //TODO change mutation rates to variables public void Mutate(EvoDrawing parent) { foreach (var point in shapePoints) { point.Mutate(parent); } //Add point to shape if (shapePoints.Count < MaxPoints && Numbers.ProbabilityFulfilled(Numbers.AddPointMutationProbability)) { parent.NeedRepaint = true; EvoPoint additionalPoint = new EvoPoint(); int i = Numbers.GetRandom(1, shapePoints.Count - 1); additionalPoint.X = Numbers.GetAverage(shapePoints[i - 1].X, shapePoints[i].X); additionalPoint.Y = Numbers.GetAverage(shapePoints[i - 1].Y, shapePoints[i].Y); shapePoints.Insert(i, additionalPoint); } //Delete point if (shapePoints.Count > MinPoints && Numbers.ProbabilityFulfilled(Numbers.RemovePointmutationProbability)) { parent.NeedRepaint = true; shapePoints.Remove( shapePoints.ElementAt <EvoPoint>( Numbers.GetRandom(0, shapePoints.Count))); } color.Mutate(parent); }
//Constructor creating a shape in memory public EvoShape(int minPoints, int maxPoints) { MinPoints = minPoints; MaxPoints = maxPoints; color = new EvoColor(); shapePoints = new List <EvoPoint>(); var center = new EvoPoint(); for (int i = 0; i < MinPoints; i++) { int X = Math.Min(Math.Max(0, center.X + Numbers.GetRandom(-3, 3)), Numbers.MaxWidth); int Y = Math.Min(Math.Max(0, center.Y + Numbers.GetRandom(-3, 3)), Numbers.MaxHeight); shapePoints.Add(new EvoPoint(X, Y)); } }