Exemple #1
0
        public override void Apply(SvgDocument SvgDocument)
        {
            NumStripes = GetNumStripes();

            Color[] stripeColors = new Color[NumStripes];

            StripeDirection = GetStripeDirection();
            EvenStripes     = NumStripes % 2 == 0;
            bool alternate = R.NextDouble() < ALTERNATING_COLORS_CHANCE;

            // Get stripe colors
            if (alternate) // Alternating colored stripes
            {
                Color c1 = ColorManager.GetRandomColor();
                Color c2 = ColorManager.GetRandomColor(new List <Color>()
                {
                    c1
                });
                for (int i = 0; i < NumStripes; i++)
                {
                    stripeColors[i] = i % 2 == 0 ? c1 : c2;
                }
            }
            else if (!EvenStripes && R.NextDouble() < UNEVEN_SYMMETRY_CHANCE) // Symmetrical colored stripes
            {
                for (int i = 0; i < NumStripes; i++)
                {
                    if (i < (NumStripes + 1) / 2)
                    {
                        stripeColors[i] = ColorManager.GetRandomColor(stripeColors.Where(x => x != null).ToList());
                    }
                    else
                    {
                        stripeColors[i] = stripeColors[NumStripes - 1 - i];
                    }
                }
            }
            else // All stripes different color
            {
                for (int i = 0; i < NumStripes; i++)
                {
                    stripeColors[i] = ColorManager.GetRandomColor(stripeColors.Where(x => x != null).ToList());
                }
            }

            float[] stripeSizes = new float[NumStripes]; // Stripe size (0-1)

            if (!EvenStripes && R.NextDouble() < WIDE_MID_STRIPE_CHANCE)
            {
                float midStripeSize    = RandomRange(MIN_MID_STRIPE_SIZE, MAX_MID_STRIPE_SIZE);
                float otherStripesSize = (1f - midStripeSize) / (NumStripes - 1);
                for (int i = 0; i < NumStripes; i++)
                {
                    if (i == NumStripes / 2)
                    {
                        stripeSizes[i] = midStripeSize;
                    }
                    else
                    {
                        stripeSizes[i] = otherStripesSize;
                    }
                }
            }
            else
            {
                for (int i = 0; i < NumStripes; i++)
                {
                    stripeSizes[i] = 1f / NumStripes;
                }
            }

            // Draw stripes
            float curRel = 0;

            for (int i = 0; i < NumStripes; i++)
            {
                float stripeSize = stripeSizes[i];

                DrawRectangle(SvgDocument,
                              StripeDirection == StripeDirectionType.Horizontal ? 0 : curRel *FlagWidth,
                              StripeDirection == StripeDirectionType.Horizontal ? curRel *FlagHeight : 0,
                              StripeDirection == StripeDirectionType.Horizontal ? FlagWidth : FlagWidth *stripeSize,
                              StripeDirection == StripeDirectionType.Horizontal ? FlagHeight *stripeSize : FlagHeight,
                              stripeColors[i]);
                curRel += stripeSize;
            }

            CoatOfArmsChance = COAT_OF_ARMS_CHANCE;

            float minCoaSize = 0, maxCoaSize = 0; // Absolute size

            switch (GetOverlayType())
            {
            case OverlayType.None:
                if (!EvenStripes && R.NextDouble() < MID_STRIPE_SYMBOLS_CHANCE)
                {
                    CoatOfArmsChance = 0f;
                    int numSymbols = RandomRange(MID_STRIPE_SYMBOLS_MIN_AMOUNT, MID_STRIPE_SYMBOLS_MAX_AMOUNT + 1);

                    Color symbolColor = ColorManager.GetRandomColor(new List <Color>()
                    {
                        stripeColors[NumStripes / 2]
                    });

                    float midStripeWidth   = stripeSizes[(NumStripes / 2)];
                    float minSymbolRelSize = Math.Min(midStripeWidth, 0.1f);
                    float maxSymbolRelSize = Math.Min(midStripeWidth, 1f / (numSymbols + 1));
                    float symbolRelSize    = RandomRange(minSymbolRelSize, maxSymbolRelSize);

                    Symbol symbol      = GetRandomSymbol();
                    float  relStepSize = 1f / (numSymbols + 1);
                    for (int i = 0; i < numSymbols; i++)
                    {
                        PointF position = new PointF(StripeDirection == StripeDirectionType.Horizontal ? (i + 1) * relStepSize * FlagWidth : FlagCenter.X, StripeDirection == StripeDirectionType.Horizontal ? FlagCenter.Y : (i + 1) * relStepSize * FlagHeight);
                        symbol.Draw(SvgDocument, this, position, StripeDirection == StripeDirectionType.Horizontal ? symbolRelSize * FlagHeight : symbolRelSize * FlagHeight, 0, symbolColor);
                    }
                }

                else     // Coat of arms
                {
                    CoatOfArmsPosition = FlagCenter;
                    List <Color> forbiddenCoaColors = EvenStripes ? new List <Color>()
                    {
                        stripeColors[NumStripes / 2 - 1], stripeColors[NumStripes / 2]
                    } : new List <Color>()
                    {
                        stripeColors[NumStripes / 2]
                    };
                    float coaSizeRel = EvenStripes ? stripeSizes[0] * 2 : stripeSizes[NumStripes / 2];
                    if (!EvenStripes && R.NextDouble() < BIG_COA_CHANCE)
                    {
                        coaSizeRel = stripeSizes[(NumStripes / 2) - 1] + stripeSizes[(NumStripes / 2)] + stripeSizes[(NumStripes / 2) + 1];
                        forbiddenCoaColors.Add(stripeColors[(NumStripes / 2) - 1]);
                        forbiddenCoaColors.Add(stripeColors[(NumStripes / 2) + 1]);
                    }

                    CoatOfArmsSize  = StripeDirection == StripeDirectionType.Horizontal ? coaSizeRel * FlagHeight : coaSizeRel * FlagWidth;
                    CoatOfArmsSize  = Math.Min(FlagHeight, CoatOfArmsSize);
                    CoatOfArmsSize *= 0.9f;
                    CoatOfArmsColor = ColorManager.GetRandomColor(forbiddenCoaColors);
                }
                break;

            case OverlayType.TopRightSquare:
                List <Color> forbiddenColors = new List <Color>();
                for (int i = 0; i <= NumStripes / 2; i++)
                {
                    forbiddenColors.Add(stripeColors[i]);
                }
                Color squareColor = ColorManager.GetRandomColor(forbiddenColors);
                DrawRectangle(SvgDocument, 0, 0, FlagWidth / 2, FlagHeight / 2, squareColor);

                // Coa
                CoatOfArmsPosition = new PointF(FlagWidth / 4, FlagHeight / 4);
                minCoaSize         = FlagHeight / 4;
                maxCoaSize         = FlagHeight / 2;
                CoatOfArmsColor    = ColorManager.GetRandomColor(new List <Color>()
                {
                    squareColor
                });
                break;

            case OverlayType.LeftTriangle:
                Color    triangleColor = ColorManager.GetRandomColor(stripeColors.ToList());
                float    triangleWidth = RandomRange(LEFT_TRIANGLE_MIN_WIDTH, LEFT_TRIANGLE_MAX_WIDTH);
                PointF[] vertices      = new PointF[]
                {
                    new PointF(0, 0), new PointF(triangleWidth * FlagWidth, FlagHeight / 2), new PointF(0, FlagHeight)
                };
                DrawPolygon(SvgDocument, vertices, triangleColor);

                // Coa
                CoatOfArmsPosition = new PointF((triangleWidth * 0.35f) * FlagWidth, FlagHeight / 2);
                minCoaSize         = (triangleWidth * 0.3f) * FlagWidth;
                maxCoaSize         = (triangleWidth * 0.6f) * FlagWidth;
                CoatOfArmsColor    = ColorManager.GetRandomColor(new List <Color>()
                {
                    triangleColor
                });
                break;

            case OverlayType.Antigua:
                Color    overlayColor = ColorManager.GetRandomColor(stripeColors.ToList());
                PointF[] triangle1    = new PointF[] { new PointF(0, 0), new PointF(FlagWidth / 2, FlagHeight), new PointF(0, FlagHeight) };
                PointF[] triangle2    = new PointF[] { new PointF(FlagWidth, 0), new PointF(FlagWidth / 2, FlagHeight), new PointF(FlagWidth, FlagHeight) };
                DrawPolygon(SvgDocument, triangle1, overlayColor);
                DrawPolygon(SvgDocument, triangle2, overlayColor);

                // Coa
                float height = RandomRange(0.2f, 0.4f);
                CoatOfArmsPosition = new PointF(FlagWidth / 2, height * FlagHeight);
                minCoaSize         = 0.2f * FlagHeight;
                maxCoaSize         = Math.Min(0.5f, height * 2f) * FlagHeight;
                CoatOfArmsColor    = ColorManager.GetRandomColor(stripeColors.ToList());
                break;
            }

            if (CoatOfArmsSize == 0)
            {
                CoatOfArmsSize = RandomRange(minCoaSize, maxCoaSize);
            }

            ApplyCoatOfArms(SvgDocument);
        }
Exemple #2
0
        public override void Apply(SvgDocument SvgDocument)
        {
            float minCoaSize = 0.5f;
            float maxCoaSize = 0.95f;

            CoatOfArmsSize     = RandomRange(minCoaSize * FlagHeight, maxCoaSize * FlagHeight);
            CoatOfArmsPosition = FlagCenter;

            CoatOfArmsChance = SPLIT_COA_CHANCE;

            switch (GetRandomStyle())
            {
            case Style.Split:
                Color c1 = ColorManager.GetRandomColor();
                Color c2 = ColorManager.GetRandomColor(new List <Color>()
                {
                    c1
                });
                CoatOfArmsColor = ColorManager.GetRandomColor(new List <Color>()
                {
                    c1, c2
                });

                PointF[] triangle1 = new PointF[] { new PointF(0, 0), new PointF(FlagWidth, 0), new PointF(0, FlagHeight) };
                PointF[] triangle2 = new PointF[] { new PointF(0, FlagHeight), new PointF(FlagWidth, 0), new PointF(FlagWidth, FlagHeight) };
                DrawPolygon(SvgDocument, triangle1, c1);
                DrawPolygon(SvgDocument, triangle2, c2);

                // Double Split
                if (R.NextDouble() < DOUBLE_SPLIT_CHANCE)
                {
                    Color c3 = ColorManager.GetRandomColor(new List <Color>()
                    {
                        c1, c2
                    });
                    float    minSplit2Start = 0.2f;
                    float    maxSplit2Start = 0.6f;
                    float    split2Start    = RandomRange(minSplit2Start, maxSplit2Start);
                    PointF[] triangle3      = new PointF[] { new PointF(FlagWidth * split2Start, FlagHeight), new PointF(FlagWidth, FlagHeight * split2Start), new PointF(FlagWidth, FlagHeight) };
                    DrawPolygon(SvgDocument, triangle3, c3);

                    CoatOfArmsColor = ColorManager.GetRandomColor(new List <Color>()
                    {
                        c1
                    });
                    minCoaSize         = 0.2f;
                    maxCoaSize         = 0.5f;
                    CoatOfArmsSize     = RandomRange(FlagHeight * minCoaSize, FlagHeight * maxCoaSize);
                    CoatOfArmsPosition = new PointF(50 + CoatOfArmsSize / 2, 50 + CoatOfArmsSize / 2);
                }

                // Top right coa
                if (R.NextDouble() < TOP_RIGHT_COA_CHANCE)
                {
                    CoatOfArmsColor = ColorManager.GetRandomColor(new List <Color>()
                    {
                        c1
                    });
                    minCoaSize         = 0.2f;
                    maxCoaSize         = 0.5f;
                    CoatOfArmsSize     = RandomRange(FlagHeight * minCoaSize, FlagHeight * maxCoaSize);
                    CoatOfArmsPosition = new PointF(50 + CoatOfArmsSize / 2, 50 + CoatOfArmsSize / 2);
                }

                break;

            case Style.Cross:
                Color bg         = ColorManager.GetRandomColor();
                Color crossColor = ColorManager.GetRandomColor(new List <Color>()
                {
                    bg
                });
                DrawRectangle(SvgDocument, 0, 0, FlagWidth, FlagHeight, bg);
                float crossWidth     = RandomRange(MIN_CROSS_WIDTH, MAX_CROSS_WIDTH);
                float crossWidthAbsX = crossWidth * FlagWidth;
                float crossWidthAbsY = crossWidth * FlagHeight;

                if (R.NextDouble() < CROSS_DIFFERENT_SIDE_COLORS_CHANCE)
                {
                    Color sideColor = ColorManager.GetRandomColor(new List <Color>()
                    {
                        bg, crossColor
                    });
                    PointF[] leftTriangle  = new PointF[] { new PointF(0, 0), FlagCenter, new PointF(0, FlagHeight) };
                    PointF[] rightTriangle = new PointF[] { new PointF(FlagWidth, 0), FlagCenter, new PointF(FlagWidth, FlagHeight) };
                    DrawPolygon(SvgDocument, leftTriangle, sideColor);
                    DrawPolygon(SvgDocument, rightTriangle, sideColor);
                }

                PointF[] cross1Vertices = new PointF[] { new PointF(0, 0), new PointF(crossWidthAbsX, 0), new PointF(FlagWidth, FlagHeight - crossWidthAbsY), new PointF(FlagWidth, FlagHeight), new PointF(FlagWidth - crossWidthAbsX, FlagHeight), new PointF(0, crossWidthAbsY) };
                PointF[] cross2Vertices = new PointF[] { new PointF(0, FlagHeight), new PointF(0, FlagHeight - crossWidthAbsY), new PointF(FlagWidth - crossWidthAbsX, 0), new PointF(FlagWidth, 0), new PointF(FlagWidth, crossWidthAbsY), new PointF(crossWidthAbsX, FlagHeight) };
                DrawPolygon(SvgDocument, cross1Vertices, crossColor);
                DrawPolygon(SvgDocument, cross2Vertices, crossColor);

                if (R.NextDouble() < INNER_CROSS_CHANCE)
                {
                    Color innerCrossColor = ColorManager.GetRandomColor(new List <Color>()
                    {
                        crossColor
                    });
                    float    innerCrossWidth     = RandomRange(crossWidth * 0.2f, crossWidth * 0.8f);
                    float    innerCrossWidthAbsX = innerCrossWidth * FlagWidth;
                    float    innerCrossWidthAbsY = innerCrossWidth * FlagHeight;
                    PointF[] innerCross1Vertices = new PointF[] { new PointF(0, 0), new PointF(innerCrossWidthAbsX, 0), new PointF(FlagWidth, FlagHeight - innerCrossWidthAbsY), new PointF(FlagWidth, FlagHeight), new PointF(FlagWidth - innerCrossWidthAbsX, FlagHeight), new PointF(0, innerCrossWidthAbsY) };
                    PointF[] innerCross2Vertices = new PointF[] { new PointF(0, FlagHeight), new PointF(0, FlagHeight - innerCrossWidthAbsY), new PointF(FlagWidth - innerCrossWidthAbsX, 0), new PointF(FlagWidth, 0), new PointF(FlagWidth, innerCrossWidthAbsY), new PointF(innerCrossWidthAbsX, FlagHeight) };
                    DrawPolygon(SvgDocument, innerCross1Vertices, innerCrossColor);
                    DrawPolygon(SvgDocument, innerCross2Vertices, innerCrossColor);
                }
                CoatOfArmsChance = 0f;
                break;
            }

            ApplyCoatOfArms(SvgDocument);
        }
Exemple #3
0
        private const float MAX_DIAMOND_FRAME_SIZE = 0.3f;  // relative to flag height

        public override void Apply(SvgDocument SvgDocument)
        {
            Style style = GetRandomStyle();

            CoatOfArmsChance   = 1f;
            CoatOfArmsPosition = FlagCenter;

            Color bgColor, secColor;
            float minCoaSizeRel = 0, maxCoaSizeRel = 0;

            switch (style)
            {
            case Style.Plain:
                bgColor         = ColorManager.GetRandomColor();
                CoatOfArmsColor = ColorManager.GetRandomColor(new List <Color>()
                {
                    bgColor
                });
                minCoaSizeRel = 0.6f;
                maxCoaSizeRel = 0.95f;
                DrawRectangle(SvgDocument, 0, 0, FlagWidth, FlagHeight, bgColor);
                break;

            case Style.Frame:
                bgColor  = ColorManager.GetRandomColor();
                secColor = ColorManager.GetRandomColor(new List <Color>()
                {
                    bgColor
                });
                CoatOfArmsColor = ColorManager.GetRandomColor(new List <Color>()
                {
                    secColor
                });
                float frameHeightRel = RandomRange(MIN_FRAME_SIZE, MAX_FRAME_SIZE);
                float frameSize      = frameHeightRel * FlagHeight;
                DrawRectangle(SvgDocument, 0, 0, FlagWidth, FlagHeight, bgColor);
                // Frame
                DrawRectangle(SvgDocument, frameSize, frameSize, FlagWidth - 2 * frameSize, FlagHeight - 2 * frameSize, secColor);

                minCoaSizeRel = 0.3f;
                maxCoaSizeRel = 1f - (2f * frameHeightRel);
                break;

            case Style.Diamond:
                bgColor  = ColorManager.GetRandomColor();
                secColor = ColorManager.GetRandomColor(new List <Color>()
                {
                    bgColor
                });
                CoatOfArmsColor = ColorManager.GetRandomColor(new List <Color>()
                {
                    secColor
                });
                float frameSizeXRel = RandomRange(0f, MAX_DIAMOND_FRAME_SIZE);
                float frameSizeYRel = RandomRange(0f, MAX_DIAMOND_FRAME_SIZE);
                float frameSizeX    = frameSizeXRel * FlagWidth;
                float frameSizeY    = frameSizeYRel * FlagHeight;
                DrawRectangle(SvgDocument, 0, 0, FlagWidth, FlagHeight, bgColor);
                // Frame
                PointF[] vertices = new PointF[]
                {
                    new PointF(FlagWidth / 2, frameSizeY),
                    new PointF(FlagWidth - frameSizeX, FlagHeight / 2),
                    new PointF(FlagWidth / 2, FlagHeight - frameSizeY),
                    new PointF(frameSizeX, FlagHeight / 2)
                };
                DrawPolygon(SvgDocument, vertices, secColor);

                minCoaSizeRel = 0.3f;
                maxCoaSizeRel = 1f - (3 * Math.Max(frameSizeXRel, frameSizeYRel));
                break;
            }



            float minCoaSize = FlagHeight * minCoaSizeRel;
            float maxCoaSize = FlagHeight * maxCoaSizeRel;

            CoatOfArmsSize = RandomRange(minCoaSize, maxCoaSize);

            ApplyCoatOfArms(SvgDocument);
        }