public static OutlineShape RandomInstance(Random r, int xSize, int ySize, double centerX, double centerY, double shapeSize)
        {
            int p = r.Next(Functions.Count);
            //p = Functions.Count - 2 + r.Next(2);
            //p = r.Next(Functions.Count - 2);
            //p = r.Next(2);
            //p = 4;
            MethodInfo   function        = Functions[p];
            TDFAttribute characteristics = Attributes[p];

            int symmetryRotation;

            if (characteristics.symmetry == 0)
            {
                symmetryRotation = 0;
            }
            else
            {
                symmetryRotation = 1 + r.Next(4 / characteristics.symmetry);
            }

            double scale = characteristics.scaleMin + r.NextDouble() * (characteristics.scaleMax - characteristics.scaleMin);

            // Call the declaring type's constructor.
            FunctionOutlineShape result = (FunctionOutlineShape)function.DeclaringType.GetConstructor(
                new Type[7] {
                typeof(int), typeof(int), typeof(double), typeof(double), typeof(double), typeof(MethodInfo), typeof(int)
            }).Invoke(
                new object[7] {
                xSize, ySize, centerX, centerY, scale * shapeSize, function, symmetryRotation
            }
                );

            result.ConfigureDistortion(function, r);
            result.ConfigureFunctionParameters(function, r);

            return(result);
        }
Exemple #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 Function(Random r, int xSize, int ySize, double centerX, double centerY, double shapeSize)
 {
     return(FunctionOutlineShape.RandomInstance(r, xSize, ySize, centerX, centerY, shapeSize));
 }