Пример #1
0
        public void Mutate(DnaDrawing drawing)
        {
            if (Tools.WillMutate(Settings.ActiveRedMutationRate))
            {
                Red = Tools.GetRandomNumber(Settings.ActiveRedRangeMin, Settings.ActiveRedRangeMax);
                drawing.SetDirty();
            }

            if (Tools.WillMutate(Settings.ActiveGreenMutationRate))
            {
                Green = Tools.GetRandomNumber(Settings.ActiveGreenRangeMin, Settings.ActiveGreenRangeMax);
                drawing.SetDirty();
            }

            if (Tools.WillMutate(Settings.ActiveBlueMutationRate))
            {
                Blue = Tools.GetRandomNumber(Settings.ActiveBlueRangeMin, Settings.ActiveBlueRangeMax);
                drawing.SetDirty();
            }

            if (Tools.WillMutate(Settings.ActiveAlphaMutationRate))
            {
                Alpha = Tools.GetRandomNumber(Settings.ActiveAlphaRangeMin, Settings.ActiveAlphaRangeMax);
                drawing.SetDirty();
            }
        }
Пример #2
0
        public void Mutate(DnaDrawing drawing)
        {
            if (Tools.WillMutate(Settings.ActiveMovePointMaxMutationRate))
            {
                X = Tools.GetRandomNumber(0, Tools.MaxWidth);
                Y = Tools.GetRandomNumber(0, Tools.MaxHeight);
                drawing.SetDirty();
            }

            if (Tools.WillMutate(Settings.ActiveMovePointMidMutationRate))
            {
                X =
                    Math.Min(
                        Math.Max(0,
                                 X +
                                 Tools.GetRandomNumber(-Settings.ActiveMovePointRangeMid,
                                                       Settings.ActiveMovePointRangeMid)), Tools.MaxWidth);
                Y =
                    Math.Min(
                        Math.Max(0,
                                 Y +
                                 Tools.GetRandomNumber(-Settings.ActiveMovePointRangeMid,
                                                       Settings.ActiveMovePointRangeMid)), Tools.MaxHeight);
                drawing.SetDirty();
            }

            if (Tools.WillMutate(Settings.ActiveMovePointMinMutationRate))
            {
                X =
                    Math.Min(
                        Math.Max(0,
                                 X +
                                 Tools.GetRandomNumber(-Settings.ActiveMovePointRangeMin,
                                                       Settings.ActiveMovePointRangeMin)), Tools.MaxWidth);
                Y =
                    Math.Min(
                        Math.Max(0,
                                 Y +
                                 Tools.GetRandomNumber(-Settings.ActiveMovePointRangeMin,
                                                       Settings.ActiveMovePointRangeMin)), Tools.MaxHeight);
                drawing.SetDirty();
            }
        }
Пример #3
0
        public void MutateOrigin(DnaDrawing drawing)
        {
            if (tool.WillMutate(Settings.ActiveMovePointMaxMutationRate))
            {
                origin.X = tool.GetRandomNumber(-Settings.ActiveMaxCircleRadius, Tools.MaxWidth + Settings.ActiveMaxCircleRadius);
                origin.Y = tool.GetRandomNumber(-Settings.ActiveMaxCircleRadius, Tools.MaxHeight + Settings.ActiveMaxCircleRadius);
                drawing.SetDirty();
            }

            if (tool.WillMutate(Settings.ActiveMovePointMidMutationRate))
            {
                origin.X =
                    Math.Min(
                        Math.Max(-Settings.ActiveMaxCircleRadius,
                                 origin.X +
                                 tool.GetRandomNumber(-Settings.ActiveMovePointRangeMid,
                                                      Settings.ActiveMovePointRangeMid)), Tools.MaxWidth + Settings.ActiveMaxCircleRadius);
                origin.Y =
                    Math.Min(
                        Math.Max(-Settings.ActiveMaxCircleRadius,
                                 origin.Y +
                                 tool.GetRandomNumber(-Settings.ActiveMovePointRangeMid,
                                                      Settings.ActiveMovePointRangeMid)), Tools.MaxHeight + Settings.ActiveMaxCircleRadius);
                drawing.SetDirty();
            }

            if (tool.WillMutate(Settings.ActiveMovePointMinMutationRate))
            {
                origin.X =
                    Math.Min(
                        Math.Max(-Settings.ActiveMaxCircleRadius,
                                 origin.X +
                                 tool.GetRandomNumber(-Settings.ActiveMovePointRangeMin,
                                                      Settings.ActiveMovePointRangeMin)), Tools.MaxWidth + Settings.ActiveMaxCircleRadius);
                origin.Y =
                    Math.Min(
                        Math.Max(-Settings.ActiveMaxCircleRadius,
                                 origin.Y +
                                 tool.GetRandomNumber(-Settings.ActiveMovePointRangeMin,
                                                      Settings.ActiveMovePointRangeMin)), Tools.MaxHeight + Settings.ActiveMaxCircleRadius);
                drawing.SetDirty();
            }
        }
Пример #4
0
        public double mutateScalar(double scalar, double min, double max, DnaDrawing drawing)
        {
            if (tool.WillMutate(Settings.ActiveCircleSizeMidMutationRate))
            {
                drawing.SetDirty();
                return(Math.Min(Math.Max(min, scalar +
                                         tool.GetRandomNumber(-Settings.ActiveCircleSizeRangeMid,
                                                              Settings.ActiveCircleSizeRangeMid)), max));
            }

            if (tool.WillMutate(Settings.ActiveCircleSizeMinMutationRate))
            {
                drawing.SetDirty();
                return(Math.Min(Math.Max(min, scalar +
                                         tool.GetRandomNumber(-Settings.ActiveCircleSizeRangeMin,
                                                              Settings.ActiveCircleSizeRangeMin)), max));
            }

            return(scalar);
        }
Пример #5
0
        private void RemovePoint(DnaDrawing drawing)
        {
            if (Points.Count > Settings.ActivePointsPerPolygonMin)
            {
                if (drawing.PointCount > Settings.ActivePointsMin)
                {
                    int index = Tools.GetRandomNumber(0, Points.Count);
                    Points.RemoveAt(index);

                    drawing.SetDirty();
                }
            }
        }
Пример #6
0
        private void AddPoint(DnaDrawing drawing)
        {
            if (Points.Count < Settings.ActivePointsPerPolygonMax)
            {
                if (drawing.PointCount < Settings.ActivePointsMax)
                {
                    var newPoint = new DnaPoint();

                    int index = Tools.GetRandomNumber(1, Points.Count - 1);

                    DnaPoint prev = Points[index - 1];
                    DnaPoint next = Points[index];

                    newPoint.X = (prev.X + next.X) / 2;
                    newPoint.Y = (prev.Y + next.Y) / 2;


                    Points.Insert(index, newPoint);

                    drawing.SetDirty();
                }
            }
        }