Пример #1
0
        public void Mutate(IDnaDrawing 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 static double GetDrawingFitness(IDnaDrawing newDrawing, Color[,] sourceColors)
        {
            double error = 0;

            using (var b = new Bitmap(Tools.MaxWidth, Tools.MaxHeight, PixelFormat.Format24bppRgb))
                using (Graphics g = Graphics.FromImage(b))
                {
                    Renderer.Render(newDrawing, g, 1);

                    BitmapData bmd1 = b.LockBits(new Rectangle(0, 0, Tools.MaxWidth, Tools.MaxHeight), ImageLockMode.ReadOnly,
                                                 PixelFormat.Format24bppRgb);


                    for (int y = 0; y < Tools.MaxHeight; y++)
                    {
                        for (int x = 0; x < Tools.MaxWidth; x++)
                        {
                            Color c1 = GetPixel(bmd1, x, y);
                            Color c2 = sourceColors[x, y];

                            double pixelError = GetColorFitness(c1, c2);
                            error += pixelError;
                        }
                    }

                    b.UnlockBits(bmd1);
                }

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

                    drawing.SetDirty();
                }
            }
        }
Пример #4
0
        public void Mutate(IDnaDrawing drawing)
        {
            if (Tools.WillMutate(Settings.ActiveAddPointMutationRate))
            {
                AddPoint(drawing);
            }

            if (Tools.WillMutate(Settings.ActiveRemovePointMutationRate))
            {
                RemovePoint(drawing);
            }

            Brush.Mutate(drawing);
            Points.ForEach(p => p.Mutate(drawing));
        }
Пример #5
0
        //Render a Drawing
        public static void Render(IDnaDrawing drawing, Graphics g, int scale)
        {
            g.Clear(Color.Black);

            if (drawing is DnaDrawing)
            {
                foreach (DnaPolygon polygon in (drawing as DnaDrawing).Polygons)
                {
                    Render(polygon, g, scale);
                }
            }
            else if (drawing is DnaCircleDrawing)
            {
                foreach (DnaCircle circle in (drawing as DnaCircleDrawing).Circles)
                {
                    Render(circle, g, scale);
                }
            }
        }
Пример #6
0
        public void Mutate(IDnaDrawing 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();
            }
        }
Пример #7
0
        private void AddPoint(IDnaDrawing 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();
                }
            }
        }
Пример #8
0
 public void Mutate(IDnaDrawing drawing)
 {
     // TODO: Implement circle mutation
 }