Esempio n. 1
0
        /// <summary>
        /// Returns a random OutlineShapeBuilder.
        /// The choice is based on few characteristics of each known OutlineShapeBuilder.
        /// </summary>
        /// <param name="r"></param>
        /// <returns></returns>
        public static OutlineShapeBuilder RandomOutlineShapeBuilder(Random r)
        {
            OutlineShapeBuilder[] shapeBuilderDelegates =
            {
                OutlineShape.Circle,
                OutlineShape.Diamond,
                OutlineShape.Polygon,
                OutlineShape.Function,
                OutlineShape.Character,
                OutlineShape.Symbol,
                OutlineShape.Bitmap,
                OutlineShape.Tiles,
                OutlineShape.Rectangles,
                OutlineShape.Grid,
                OutlineShape.GridElement,
                OutlineShape.Maze,
                OutlineShape.Circles,
                OutlineShape.Lines,
            };
            int[] ratios =   // (number of items) * (novelty value) / (easyness of recognition)
            {
                7 * 12 / 3,
                1 * 5 / 4,
                (2 * (10 + 8 + 6 + 4 + 2)) * 7 / 3,
                (3 * 8 + 2) * 12 / 2,
                15 * 10 / 2,
                8 * 15 / 2,
                25 * 15 / 1,
                8 * 12 / 3,
                3 * 6 / 3,
                7 * 10 / 2,
                7 * 8 / 2,
                2 * 20 / 1,
                1 * 12 / 2,
                1 * 8 / 2,
            };

            int n = 0;

            foreach (int k in ratios)
            {
                n += k;
            }
            int p = r.Next(n);
            //p = n - 1;

            OutlineShapeBuilder result = null;

            for (int i = 0; i < ratios.Length; i++)
            {
                if ((p -= ratios[i]) < 0)
                {
                    result = shapeBuilderDelegates[i];
                    break;
                }
            }

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a shape using a random OutlineShapeBuilder.
        /// If applicable, the shape may be distorted.
        /// </summary>
        /// <param name="r"></param>
        /// <param name="xSize"></param>
        /// <param name="ySize"></param>
        /// <param name="offCenter"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        public static OutlineShape RandomInstance(Random r, int xSize, int ySize, double offCenter, double size)
        {
            OutlineShapeBuilder outlineShapeBuilder = RandomOutlineShapeBuilder(r);

            OutlineShape result = RandomInstance(r, outlineShapeBuilder, xSize, ySize, offCenter, size);

            // If applicable, replace the shape with a distorted version.
            if (r.Next(100) < result.DistortedPercentage(33))
            {
                result = result.DistortedCopy(r);
            }

            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a shape using the given OutlineShapeBuilder.
        /// This shape will not be distorted.
        /// </summary>
        /// <param name="r"></param>
        /// <param name="outlineShapeBuilder"></param>
        /// <param name="xSize"></param>
        /// <param name="ySize"></param>
        /// <param name="offCenter"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        public static OutlineShape RandomInstance(Random r, OutlineShapeBuilder outlineShapeBuilder, int xSize, int ySize, double offCenter, double size)
        {
            double centerX = 0.5, centerY = 0.5;

            double dx = r.NextDouble() - 0.5, dy = r.NextDouble() - 0.5;

            centerX += offCenter * dx;
            centerY += offCenter * dy;

            // Reduce size when we are closer to the center than requested.
            double f = 1.0 - offCenter * 2.0 * (0.5 - Math.Max(Math.Abs(dx), Math.Abs(dy)));

            OutlineShape result = outlineShapeBuilder(r, xSize, ySize, centerX, centerY, size * f);

            return(result);
        }