/// <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); }
/// <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); }
/// <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); }
/// <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); }