Exemplo n.º 1
0
        /// <summary>
        /// Builds a pattern of interwoven ribbons, effectually forming I-beam shapes.
        /// </summary>
        /// <param name="r"></param>
        /// <param name="xSize"></param>
        /// <param name="ySize"></param>
        /// <param name="broadRibbon">When true/false, the middle beam is broader/slimmer than the end beams.</param>
        /// <returns></returns>
        private static OutlineShape Ribbons6(Random r, int xSize, int ySize, bool broadRibbon)
        {
            TilesOutlineShape result = new TilesOutlineShape(xSize, ySize, Resources.Resources.Ribbons6);

            #region Extend the shape width.

            int r1, r2;

            if (broadRibbon == true)
            {
                r1 = r.Next(6, 21);                                 // the broad ribbon width: 6..20
                r2 = Math.Max(1, Math.Min(3, r.Next(1 + r1 / 3)));  // the ribbon border: 1..3
            }
            else
            {
                r1 = r.Next(1, 5);                                  // the slim ribbon width / middle beam
                r2 = r.Next(6, 11);                                 // the ribbon border / end beam
            }

            result.SetRepetitions(r2);
            result.SetRepetitions(1, r1);
            result.SetRepetitions(4, r1);

            #endregion

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Builds a pattern of thin lines and broad stripes (horizontal or vertical).
        /// When the lines go in botth directions, they form a square or rectangular grid.
        /// </summary>
        /// <param name="r"></param>
        /// <param name="xSize"></param>
        /// <param name="ySize"></param>
        /// <returns></returns>
        private static OutlineShape StripesOrGrid(Random r, int xSize, int ySize)
        {
            TilesOutlineShape result = new TilesOutlineShape(xSize, ySize, 2, 2);

            int k = r.Next(1, 4);                              // 1, 2, 3

            result.SetValue(0, 0, (k != 3 || r.Next(2) == 0)); // maybe a disconnected grid
            result.SetValue(0, 1, ((k & 1) != 0));             // horizontal lines
            result.SetValue(1, 0, ((k & 2) != 0));             // vertical lines
            result.SetValue(1, 1, false);

            result.SetRepetitions(0, 1);                        // one-square pinstripes
            if (r.Next(0) == 0)
            {
                result.SetRepetitions(1, r.Next(4, 16));        // same x and y width
            }
            else
            {
                while (Math.Abs(result.xRepetitions[1] - result.yRepetitions[1]) < 5)
                {
                    result.SetXRepetitions(1, r.Next(4, 21));   // different x and y width
                    result.SetYRepetitions(1, r.Next(4, 21));
                }
            }

            if (result.tile[0, 0] == false && result.xRepetitions[1] > 7 && result.yRepetitions[1] > 7)
            {
                result.SetRepetitions(0, r.Next(1, 3));         // thin stripes: one or two squares
            }

            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Builds a pattern of interwoven ribbons, effectually forming rectangular frames.
        /// </summary>
        /// <param name="r"></param>
        /// <param name="xSize"></param>
        /// <param name="ySize"></param>
        /// <returns></returns>
        private static OutlineShape Ribbons8(Random r, int xSize, int ySize)
        {
            TilesOutlineShape result = new TilesOutlineShape(xSize, ySize, Resources.Resources.Ribbons8);

            #region Optionally, erase some lines completely; the shape will no longer be totally connected.

            if (r.Next(2) == 0)
            {
                for (int i = 0; i < 8; i++)
                {
                    result.SetValue(1, i, false);
                    result.SetValue(5, i, false);
                }
            }
            if (r.Next(2) == 0)
            {
                for (int i = 0; i < 8; i++)
                {
                    result.SetValue(i, 1, false);
                    result.SetValue(i, 5, false);
                }
            }

            // with one set erased: rectangular frames
            // with two sets erased: disconnected bars

            #endregion

            #region Extend the shape width.

            int r3 = r.Next(6, 21);                 // the broad ribbon width
            int r2 = 1 + r.Next(2);                 // the ribbon border
            int r1 = r3 / 6 + (r.Next(3) - 1);      // the distance between parallel ribbons

            for (int i = 2; i < 8; i += 4)
            {
                result.SetRepetitions(i - 1, r1);
                result.SetRepetitions(i + 1, r3);
            }

            for (int i = 0; i < 8; i += 2)
            {
                result.SetRepetitions(i, r2);
            }

            #endregion

            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Builds a pattern from the given bitmap, rotated and scaled.
        /// </summary>
        /// <param name="xSize"></param>
        /// <param name="ySize"></param>
        /// <param name="bitmap"></param>
        /// <param name="rft"></param>
        /// <param name="scale"></param>
        /// <returns></returns>
        private static OutlineShape FromBitmap(int xSize, int ySize, Bitmap bitmap, RotateFlipType rft, int scale)
        {
#if false
            System.Console.Out.WriteLine("[TilesOutlineShape.FromBitmap] " + rft.ToString() + ", x" + scale.ToString());
#endif

#if false
            // Note: Some bitmaps are useless (all black or all white) after the RotateFlip() operation!
            Bitmap template = (Bitmap)bitmap.Clone();
            template.RotateFlip(rft);
            TilesOutlineShape result = new TilesOutlineShape(xSize, ySize, template);
#else
            OutlineShape      tile   = new ExplicitOutlineShape(bitmap).RotatedOrFlipped(rft);
            TilesOutlineShape result = new TilesOutlineShape(xSize, ySize, tile as ExplicitOutlineShape);
#endif
            result.SetRepetitions(scale);

            return(result);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Create an outline shape.
 /// </summary>
 /// <param name="r"></param>
 /// <param name="xSize"></param>
 /// <param name="ySize"></param>
 /// <param name="centerX"></param>
 /// <param name="centerY"></param>
 /// <param name="shapeSize"></param>
 /// <returns></returns>
 public static OutlineShape Tiles(Random r, int xSize, int ySize, double centerX, double centerY, double shapeSize)
 {
     return(TilesOutlineShape.CreateInstance(r, xSize, ySize));
 }
Exemplo n.º 6
0
        /// <summary>
        /// Builds a pattern made of pentominoes: five adjoining squares in different arrangements.
        /// </summary>
        /// <param name="r"></param>
        /// <param name="xSize"></param>
        /// <param name="ySize"></param>
        /// <returns></returns>
        private static OutlineShape Pentominoes(Random r, int xSize, int ySize)
        {
            int squareWidth = r.Next(2, 7);
            int xDim = 3 + xSize / (1 + squareWidth), yDim = 3 + xSize / (1 + squareWidth);

            TilesOutlineShape result = new TilesOutlineShape(xSize, ySize, 1 + 2 * xDim, 1 + 2 * yDim);

            PentominoPattern pentominoPattern = new PentominoPattern(r, xDim, yDim);

            #region Start with filled squares in all but the (odd,odd) positions.

            for (int x = 0; x < result.xTileSize; x++)
            {
                for (int y = 0; y < result.yTileSize; y++)
                {
                    result.SetValue(x, y, (x % 2 == 0 || y % 2 == 0));
                }
            }

            // result: a dense grid

            /*
             *   x x x x x x x x
             *   x o x o x o x o
             *   x x x x x x x x
             *   x o x o x o x o
             *   x x x x x x x x
             *   x o x o x o x o
             *   x x x x x x x x
             *   x o x o x o x o
             */

            for (int x = 1; x < xDim; x++)
            {
                result.SetXRepetitions(1 + 2 * x, squareWidth);
            }
            for (int y = 1; y < yDim; y++)
            {
                result.SetYRepetitions(1 + 2 * y, squareWidth);
            }

            #endregion

            #region Open the positions between pentomino squares of the same id.

            for (int x = 0; x < xDim; x++)
            {
                for (int y = 0; y < yDim; y++)
                {
                    if (x + 1 < xDim && pentominoPattern[x, y] == pentominoPattern[x + 1, y])
                    {
                        result.SetValue(2 + 2 * x, 1 + 2 * y, false);
                    }
                    if (y + 1 < yDim && pentominoPattern[x, y] == pentominoPattern[x, y + 1])
                    {
                        result.SetValue(1 + 2 * x, 2 + 2 * y, false);
                    }
                }
            }

            #endregion

            return(result);
        }