Clone() public method

public Clone ( ) : object
return object
Esempio n. 1
0
        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;
            }
        }
Esempio n. 2
0
        void ChangeColor(Random rand, Shape shape, TaskState task)
        {
            shape.PreviousState = shape.Clone() as Shape;
            int delta = rand.NextByte(1, (int)(MaxColorDelta + 1)) * (rand.Next(2) == 0 ? 1 : -1);

            switch (rand.Next(4))
            {
            case 0:
                shape.Color =
                    Color.FromArgb(
                        Math.Max(task.ProjectOptions.MinAlpha, Math.Min(255, shape.Color.A + delta)),
                        shape.Color.R, shape.Color.G, shape.Color.B);
                break;

            case 1:
                shape.Color = Color.FromArgb(shape.Color.A, Math.Max(0, Math.Min(255, shape.Color.R + delta)),
                                             shape.Color.G, shape.Color.B);
                break;

            case 2:
                shape.Color = Color.FromArgb(shape.Color.A, shape.Color.R,
                                             Math.Max(0, Math.Min(255, shape.Color.G + delta)), shape.Color.B);
                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 + delta)));
                break;
            }
        }
Esempio n. 3
0
        static void RandomizeShape(Random rand, Shape shape, TaskState task)
        {
            int maxOverlap = task.ProjectOptions.MaxOverlap;

            shape.PreviousState = shape.Clone() as Shape;
            shape.Color         = Color.FromArgb(rand.Next(task.ProjectOptions.MinAlpha, 256), rand.Next(256),
                                                 rand.Next(256), rand.Next(256));
            for (int i = 0; i < shape.Points.Length; i++)
            {
                shape.Points[i] = new PointF(rand.NextFloat(-maxOverlap, task.ImageWidth + maxOverlap),
                                             rand.NextFloat(-maxOverlap, task.ImageHeight + maxOverlap));
            }
        }
Esempio n. 4
0
        void MutateShape(Random rand, DNA dna, Shape shape, TaskState task)
        {
            shape.PreviousState = shape.Clone() as Shape;
            switch (rand.Next(10))
            {
            case 0:
                shape.Color = Color.FromArgb((byte)rand.Next(task.ProjectOptions.MinAlpha, 256), shape.Color.R,
                                             shape.Color.G, shape.Color.B);
                dna.LastMutation = MutationType.ReplaceColor;
                if (rand.Next(10) == 0)
                {
                    MutateMultiplePoints(shape, rand, dna, task);
                    dna.LastMutation = MutationType.ReplaceShape;
                }
                break;

            case 1:
                shape.Color      = Color.FromArgb(shape.Color.A, rand.NextByte(), shape.Color.G, shape.Color.B);
                dna.LastMutation = MutationType.ReplaceColor;
                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, rand.NextByte(), shape.Color.B);
                dna.LastMutation = MutationType.ReplaceColor;
                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, rand.NextByte());
                dna.LastMutation = MutationType.ReplaceColor;
                if (rand.Next(10) == 0)
                {
                    MutateMultiplePoints(shape, rand, dna, task);
                    dna.LastMutation = MutationType.ReplaceShape;
                }
                break;

            default:
                MutateMultiplePoints(shape, rand, dna, task);
                break;
            }
        }
Esempio n. 5
0
        static void MutateShape(Random rand, DNA dna, Shape shape, TaskState task)
        {
            int maxOverlap = task.ProjectOptions.MaxOverlap;

            shape.PreviousState = shape.Clone() as Shape;
            switch (rand.Next(9))
            {
            case 0:
                shape.Color = Color.FromArgb((byte)rand.Next(task.ProjectOptions.MinAlpha, 256), shape.Color.R,
                                             shape.Color.G, shape.Color.B);
                dna.LastMutation = MutationType.ReplaceColor;
                break;

            case 1:
                shape.Color      = Color.FromArgb(shape.Color.A, (byte)rand.Next(256), shape.Color.G, shape.Color.B);
                dna.LastMutation = MutationType.ReplaceColor;
                break;

            case 2:
                shape.Color      = Color.FromArgb(shape.Color.A, shape.Color.R, (byte)rand.Next(256), shape.Color.B);
                dna.LastMutation = MutationType.ReplaceColor;
                break;

            case 3:
                shape.Color      = Color.FromArgb(shape.Color.A, shape.Color.R, shape.Color.G, (byte)rand.Next(256));
                dna.LastMutation = MutationType.ReplaceColor;
                break;

            case 4:
            case 5:
                shape.Points[rand.Next(shape.Points.Length)].X = rand.NextFloat(-maxOverlap,
                                                                                task.ImageWidth + maxOverlap);
                dna.LastMutation = MutationType.ReplacePoint;
                break;

            case 6:
            case 7:
                shape.Points[rand.Next(shape.Points.Length)].Y = rand.NextFloat(-maxOverlap,
                                                                                task.ImageHeight + maxOverlap);
                dna.LastMutation = MutationType.ReplacePoint;
                break;

            case 8:
                shape.Points[rand.Next(shape.Points.Length)].X = rand.NextFloat(-maxOverlap,
                                                                                task.ImageWidth + maxOverlap);
                shape.Points[rand.Next(shape.Points.Length)].Y = rand.NextFloat(-maxOverlap,
                                                                                task.ImageHeight + maxOverlap);
                dna.LastMutation = MutationType.ReplacePoints;
                break;
            }
        }
Esempio n. 6
0
 static void MutateShape( Random rand, DNA dna, Shape shape, TaskState task )
 {
     int maxOverlap = task.ProjectOptions.MaxOverlap;
     shape.PreviousState = shape.Clone() as Shape;
     switch( rand.Next( 9 ) ) {
         case 0:
             shape.Color = Color.FromArgb( (byte)rand.Next( task.ProjectOptions.MinAlpha, 256 ), shape.Color.R,
                                           shape.Color.G, shape.Color.B );
             dna.LastMutation = MutationType.ReplaceColor;
             break;
         case 1:
             shape.Color = Color.FromArgb( shape.Color.A, (byte)rand.Next( 256 ), shape.Color.G, shape.Color.B );
             dna.LastMutation = MutationType.ReplaceColor;
             break;
         case 2:
             shape.Color = Color.FromArgb( shape.Color.A, shape.Color.R, (byte)rand.Next( 256 ), shape.Color.B );
             dna.LastMutation = MutationType.ReplaceColor;
             break;
         case 3:
             shape.Color = Color.FromArgb( shape.Color.A, shape.Color.R, shape.Color.G, (byte)rand.Next( 256 ) );
             dna.LastMutation = MutationType.ReplaceColor;
             break;
         case 4:
         case 5:
             shape.Points[rand.Next( shape.Points.Length )].X = rand.NextFloat( -maxOverlap,
                                                                                task.ImageWidth + maxOverlap );
             dna.LastMutation = MutationType.ReplacePoint;
             break;
         case 6:
         case 7:
             shape.Points[rand.Next( shape.Points.Length )].Y = rand.NextFloat( -maxOverlap,
                                                                                task.ImageHeight + maxOverlap );
             dna.LastMutation = MutationType.ReplacePoint;
             break;
         case 8:
             shape.Points[rand.Next( shape.Points.Length )].X = rand.NextFloat( -maxOverlap,
                                                                                task.ImageWidth + maxOverlap );
             shape.Points[rand.Next( shape.Points.Length )].Y = rand.NextFloat( -maxOverlap,
                                                                                task.ImageHeight + maxOverlap );
             dna.LastMutation = MutationType.ReplacePoints;
             break;
     }
 }
        static void ChangeColor(Random rand, Shape shape, TaskState task)
        {
            shape.PreviousState = shape.Clone() as Shape;
            switch (rand.Next(4))
            {
            case 0:
                shape.Color = Color.FromArgb(rand.NextByte(task.ProjectOptions.MinAlpha, 256), shape.Color.R,
                                             shape.Color.G, shape.Color.B);
                break;

            case 1:
                shape.Color = Color.FromArgb(shape.Color.A, rand.NextByte(), shape.Color.G, shape.Color.B);
                break;

            case 2:
                shape.Color = Color.FromArgb(shape.Color.A, shape.Color.R, rand.NextByte(), shape.Color.B);
                break;

            case 3:
                shape.Color = Color.FromArgb(shape.Color.A, shape.Color.R, shape.Color.G, rand.NextByte());
                break;
            }
        }
Esempio n. 8
0
        public void SwapShapes(Random rand)
        {
            int   s1    = rand.Next(Shapes.Length);
            Shape shape = Shapes[s1];

            shape.PreviousState = shape.Clone() as Shape;
            if (rand.Next(2) == 0)
            {
                int s2;
                do
                {
                    s2 = rand.Next(Shapes.Length);
                } while (s1 == s2);
                ShiftShapeIndex(s1, s2);
            }
            else
            {
                int s2 = rand.Next(Shapes.Length);
                Shapes[s1] = Shapes[s2];
                Shapes[s2] = shape;
            }
            LastMutation = MutationType.SwapShapes;
        }
Esempio n. 9
0
        public DNA Mutate(Random rand, DNA oldDNA, TaskState task)
        {
            int   maxOverlap = task.ProjectOptions.MaxOverlap;
            DNA   newDNA     = new DNA(oldDNA);
            Shape shape      = newDNA.Shapes[rand.Next(newDNA.Shapes.Length)];

            shape.PreviousState = shape.Clone() as Shape;
            shape.Color         = Color.FromArgb(rand.Next(task.ProjectOptions.MinAlpha, 256), rand.NextByte(),
                                                 rand.NextByte(), rand.NextByte());
            double area, maxArea = MaxPolygonArea * task.ImageWidth * task.ImageHeight;

            do
            {
                for (int i = 0; i < shape.Points.Length; i++)
                {
                    shape.Points[i] = new PointF(rand.NextFloat(-maxOverlap, task.ImageWidth + maxOverlap),
                                                 rand.NextFloat(-maxOverlap, task.ImageHeight + maxOverlap));
                }
                area = CalculateArea(shape.Points);
            } while(area > maxArea);
            newDNA.LastMutation = MutationType.ReplaceShape;
            return(newDNA);
        }
Esempio n. 10
0
 void MutateShape( Random rand, DNA dna, Shape shape, TaskState task )
 {
     int maxOverlap = task.ProjectOptions.MaxOverlap;
     shape.PreviousState = shape.Clone() as Shape;
     int colorDelta = (byte)rand.Next( 1, MaxColorDelta + 1 ) * ( rand.Next( 2 ) == 0 ? 1 : -1 );
     float posDelta = (float)rand.NextDouble() * MaxPosDelta * ( rand.Next( 2 ) == 0 ? 1 : -1 );
     switch( rand.Next( 9 ) ) {
         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;
             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;
             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;
             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;
             break;
         case 4:
         case 5:
             int pt1 = rand.Next( shape.Points.Length );
             shape.Points[pt1].X = Math.Max( -maxOverlap,
                                             Math.Min( task.ImageWidth - 1 + maxOverlap,
                                                       shape.Points[pt1].X + posDelta ) );
             dna.LastMutation = MutationType.AdjustPoint;
             break;
         case 6:
         case 7:
             int pt2 = rand.Next( shape.Points.Length );
             shape.Points[pt2].Y = Math.Max( -maxOverlap,
                                             Math.Min( task.ImageHeight - 1 + maxOverlap,
                                                       shape.Points[pt2].Y + posDelta ) );
             dna.LastMutation = MutationType.AdjustPoint;
             break;
         case 8:
             int pt3 = rand.Next( shape.Points.Length );
             shape.Points[pt3].X = Math.Max( -maxOverlap,
                                             Math.Min( task.ImageWidth - 1 + maxOverlap,
                                                       shape.Points[pt3].X + posDelta ) );
             shape.Points[pt3].Y = Math.Max( -maxOverlap,
                                             Math.Min( task.ImageHeight - 1 + maxOverlap,
                                                       shape.Points[pt3].Y + posDelta ) );
             dna.LastMutation = MutationType.AdjustPoints;
             break;
     }
 }
Esempio n. 11
0
        public DNA Mutate(Random rand, DNA oldDNA, TaskState task)
        {
            DNA newDNA = new DNA(oldDNA);

            Shape shape  = newDNA.Shapes[rand.Next(newDNA.Shapes.Length)];
            int   choice = rand.Next((EnableRotation ? 16 : 12));

            switch (choice)
            {
            case 0:
            case 1:
                shape.PreviousState = shape.Clone() as Shape;
                MoveShape(rand, shape, task);
                newDNA.LastMutation = MutationType.Move;
                break;

            case 2:
            case 3:
                shape.PreviousState = shape.Clone() as Shape;
                ScaleShape(rand, shape, task);
                newDNA.LastMutation = MutationType.Scale;
                break;

            case 4:
                shape.PreviousState = shape.Clone() as Shape;
                ScaleShape(rand, shape, task);
                MoveShape(rand, shape, task);
                newDNA.LastMutation = MutationType.Transform;
                break;

            case 5:
                shape.PreviousState = shape.Clone() as Shape;
                MoveShape(rand, shape, task);
                ScaleShape(rand, shape, task);
                newDNA.LastMutation = MutationType.Transform;
                break;

            case 6:
            case 7:
            case 8:
            case 9:
                shape.PreviousState = shape.Clone() as Shape;
                ChangeColor(rand, shape, task);
                newDNA.LastMutation = MutationType.AdjustColor;
                break;

            case 10:
                newDNA.SwapShapes(rand);
                break;

            case 11:
                shape.PreviousState = shape.Clone() as Shape;
                MoveShape(rand, shape, task);
                ScaleShape(rand, shape, task);
                ChangeColor(rand, shape, task);
                newDNA.LastMutation = MutationType.Transform;
                break;

            case 12:
            case 13:
                shape.PreviousState = shape.Clone() as Shape;
                RotateShape(rand, shape);
                newDNA.LastMutation = MutationType.Rotate;
                break;

            case 14:
                shape.PreviousState = shape.Clone() as Shape;
                MoveShape(rand, shape, task);
                RotateShape(rand, shape);
                newDNA.LastMutation = MutationType.Transform;
                break;

            case 15:
                shape.PreviousState = shape.Clone() as Shape;
                ChangeColor(rand, shape, task);
                newDNA.LastMutation = MutationType.AdjustColor;
                break;
            }
            return(newDNA);
        }
 void ChangeColor( Random rand, Shape shape, TaskState task )
 {
     shape.PreviousState = shape.Clone() as Shape;
     int delta = rand.NextByte( 1, (int)( MaxColorDelta + 1 ) ) * ( rand.Next( 2 ) == 0 ? 1 : -1 );
     switch( rand.Next( 4 ) ) {
         case 0:
             shape.Color =
                 Color.FromArgb(
                     Math.Max( task.ProjectOptions.MinAlpha, Math.Min( 255, shape.Color.A + delta ) ),
                     shape.Color.R, shape.Color.G, shape.Color.B );
             break;
         case 1:
             shape.Color = Color.FromArgb( shape.Color.A, Math.Max( 0, Math.Min( 255, shape.Color.R + delta ) ),
                                           shape.Color.G, shape.Color.B );
             break;
         case 2:
             shape.Color = Color.FromArgb( shape.Color.A, shape.Color.R,
                                           Math.Max( 0, Math.Min( 255, shape.Color.G + delta ) ), shape.Color.B );
             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 + delta ) ) );
             break;
     }
 }
 static void ChangeColor( Random rand, Shape shape, TaskState task )
 {
     shape.PreviousState = shape.Clone() as Shape;
     switch( rand.Next( 4 ) ) {
         case 0:
             shape.Color = Color.FromArgb( rand.NextByte( task.ProjectOptions.MinAlpha, 256 ), shape.Color.R,
                                           shape.Color.G, shape.Color.B );
             break;
         case 1:
             shape.Color = Color.FromArgb( shape.Color.A, rand.NextByte(), shape.Color.G, shape.Color.B );
             break;
         case 2:
             shape.Color = Color.FromArgb( shape.Color.A, shape.Color.R, rand.NextByte(), shape.Color.B );
             break;
         case 3:
             shape.Color = Color.FromArgb( shape.Color.A, shape.Color.R, shape.Color.G, rand.NextByte() );
             break;
     }
 }
Esempio n. 14
0
        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;
            }
        }
Esempio n. 15
0
 static void RandomizeShape( Random rand, Shape shape, TaskState task )
 {
     int maxOverlap = task.ProjectOptions.MaxOverlap;
     shape.PreviousState = shape.Clone() as Shape;
     shape.Color = Color.FromArgb( rand.Next( task.ProjectOptions.MinAlpha, 256 ), rand.Next( 256 ),
                                   rand.Next( 256 ), rand.Next( 256 ) );
     for( int i = 0; i < shape.Points.Length; i++ ) {
         shape.Points[i] = new PointF( rand.NextFloat( -maxOverlap, task.ImageWidth + maxOverlap ),
                                       rand.NextFloat( -maxOverlap, task.ImageHeight + maxOverlap ) );
     }
 }
Esempio n. 16
0
        void MutateShape(Random rand, DNA dna, Shape shape, TaskState task)
        {
            int maxOverlap = task.ProjectOptions.MaxOverlap;

            shape.PreviousState = shape.Clone() as Shape;
            int   colorDelta = (byte)rand.Next(1, MaxColorDelta + 1) * (rand.Next(2) == 0 ? 1 : -1);
            float posDelta   = (float)rand.NextDouble() * MaxPosDelta * (rand.Next(2) == 0 ? 1 : -1);

            switch (rand.Next(9))
            {
            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;
                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;
                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;
                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;
                break;

            case 4:
            case 5:
                int pt1 = rand.Next(shape.Points.Length);
                shape.Points[pt1].X = Math.Max(-maxOverlap,
                                               Math.Min(task.ImageWidth - 1 + maxOverlap,
                                                        shape.Points[pt1].X + posDelta));
                dna.LastMutation = MutationType.AdjustPoint;
                break;

            case 6:
            case 7:
                int pt2 = rand.Next(shape.Points.Length);
                shape.Points[pt2].Y = Math.Max(-maxOverlap,
                                               Math.Min(task.ImageHeight - 1 + maxOverlap,
                                                        shape.Points[pt2].Y + posDelta));
                dna.LastMutation = MutationType.AdjustPoint;
                break;

            case 8:
                int pt3 = rand.Next(shape.Points.Length);
                shape.Points[pt3].X = Math.Max(-maxOverlap,
                                               Math.Min(task.ImageWidth - 1 + maxOverlap,
                                                        shape.Points[pt3].X + posDelta));
                shape.Points[pt3].Y = Math.Max(-maxOverlap,
                                               Math.Min(task.ImageHeight - 1 + maxOverlap,
                                                        shape.Points[pt3].Y + posDelta));
                dna.LastMutation = MutationType.AdjustPoints;
                break;
            }
        }
Esempio n. 17
0
        void MutateShape( Random rand, DNA dna, Shape shape, TaskState task )
        {
            shape.PreviousState = shape.Clone() as Shape;
            switch( rand.Next( 10 ) ) {
                case 0:
                    shape.Color = Color.FromArgb( (byte)rand.Next( task.ProjectOptions.MinAlpha, 256 ), shape.Color.R,
                                                  shape.Color.G, shape.Color.B );
                    dna.LastMutation = MutationType.ReplaceColor;
                    if( rand.Next( 10 ) == 0 ) {
                        MutateMultiplePoints( shape, rand, dna, task );
                        dna.LastMutation = MutationType.ReplaceShape;
                    }
                    break;

                case 1:
                    shape.Color = Color.FromArgb( shape.Color.A, rand.NextByte(), shape.Color.G, shape.Color.B );
                    dna.LastMutation = MutationType.ReplaceColor;
                    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, rand.NextByte(), shape.Color.B );
                    dna.LastMutation = MutationType.ReplaceColor;
                    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, rand.NextByte() );
                    dna.LastMutation = MutationType.ReplaceColor;
                    if( rand.Next( 10 ) == 0 ) {
                        MutateMultiplePoints( shape, rand, dna, task );
                        dna.LastMutation = MutationType.ReplaceShape;
                    }
                    break;

                default:
                    MutateMultiplePoints( shape, rand, dna, task );
                    break;
            }
        }