Esempio n. 1
0
        /// <summary>
        /// Returns a polygon shape with 3 to 12 corners.
        /// </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 Random(Random r, int xSize, int ySize, double centerX, double centerY, double shapeSize)
        {
            // We build polygons with up to 12 corners.
            int    corners = 3 + r.Next(10);
            int    windings;
            double slant = 0;

            // For high number of corners, we prefer star shapes.
            // 5 corners: 50% / 12 corners: 99%
            if (corners > 4 && r.Next(100) < 50 + (corners - 5) * 7)
            {
                // Build a star shaped polygon.
                windings = 2 + r.Next((corners - 3) / 2);
            }
            else
            {
                // Build a regular polygon.
                windings = 1;
            }

            // Apply a random rotation of the whole shape.
            // 3 corners: 55% / 12 corners: 10%
            if (r.Next(100) < 70 - corners * 5)
            {
                slant = 2.0 * Math.PI * r.NextDouble();
            }
            else
            {
                // Rotate by half the rotation symmetry angle.
                // This brings a corner (instead of an edge) to the south; applies to all shapes.
                if (r.Next(100) < 50)
                {
                    slant = 2.0 * Math.PI / corners / 2;
                }

                // Rotate by 90 degrees.
                // This has no effect when corners is a multiple of four.
                // For an even number of corners, the effect is the same as the previous rotation, i.e. neutral.
                // For an odd number of corners, the edge is rotated from south/north to east/west.
                if (r.Next(100) < 50)
                {
                    slant += Math.PI / 4.0;
                }
            }

            PolygonOutlineShape result = new PolygonOutlineShape(corners, windings, slant, xSize, ySize, centerX, centerY, shapeSize);

            return(result);
        }
Esempio n. 2
0
 /// <summary>
 /// Create an outline shape.
 /// </summary>
 /// <param name="r">a source of random numbers</param>
 /// <param name="xSize">width of the created shape</param>
 /// <param name="ySize">height of the created shape</param>
 /// <param name="centerX">X coordinate, relative to total width; 0.0 = top, 1.0 = bottom</param>
 /// <param name="centerY">Y coordinate, relative to total height; 0.0 = left, 1.0 = right</param>
 /// <param name="shapeSize">size, relative to distance of center from the border; 1.0 will touch the border </param>
 /// <returns></returns>
 public static OutlineShape Polygon(Random r, int xSize, int ySize, double centerX, double centerY, double shapeSize)
 {
     return(PolygonOutlineShape.Random(r, xSize, ySize, centerX, centerY, shapeSize));
 }