コード例 #1
0
 public ComputedFractalValue()
 {
     myFractalColorValue     = new FractalColorValue(0, 0, 0, 0);
     myListOfScreenPositions = new List <Point>();
     myListOfPlanePositions  = new List <PointInPlane>();
     myTypeOfShape           = TypesOfShape.None;
 }
コード例 #2
0
        private void WriteColorToConfigurationXml(XmlWriter xmlWriterIn, FractalColorValue fractalColorValueIn)
        {
            xmlWriterIn.WriteElementString("A", Convert.ToString(fractalColorValueIn.alpha, CultureInfo.InvariantCulture));

            xmlWriterIn.WriteElementString("R", Convert.ToString(fractalColorValueIn.red, CultureInfo.InvariantCulture));

            xmlWriterIn.WriteElementString("G", Convert.ToString(fractalColorValueIn.green, CultureInfo.InvariantCulture));

            xmlWriterIn.WriteElementString("B", Convert.ToString(fractalColorValueIn.blue, CultureInfo.InvariantCulture));
        }
コード例 #3
0
        // to static methods for linear interpolation of color
        public static FractalColorValue InterpolateColor(double valueIn, double minimumValueIn, double maximumValueIn, FractalColorValue color1In, FractalColorValue color2In)
        {
            FractalColorValue aInterpolatedColor = new FractalColorValue();

            aInterpolatedColor.alpha = (int)(color1In.alpha + (double)(color2In.alpha - color1In.alpha) * Math.Abs(valueIn - minimumValueIn) / Math.Abs(maximumValueIn - minimumValueIn));
            aInterpolatedColor.red   = (int)(color1In.red + (double)(color2In.red - color1In.red) * Math.Abs(valueIn - minimumValueIn) / Math.Abs(maximumValueIn - minimumValueIn));
            aInterpolatedColor.green = (int)(color1In.green + (double)(color2In.green - color1In.green) * Math.Abs(valueIn - minimumValueIn) / Math.Abs(maximumValueIn - minimumValueIn));
            aInterpolatedColor.blue  = (int)(color1In.blue + (double)(color2In.blue - color1In.blue) * Math.Abs(valueIn - minimumValueIn) / Math.Abs(maximumValueIn - minimumValueIn));

            return(aInterpolatedColor);
        }
コード例 #4
0
        public ComputedFractalValues ReturnComputedFractalValues(RectangleInPlane fractalRectangleIn, int xMaxIn, int yMaxIn, IList <FractalColorValue> fractalColorValuesIn, System.Windows.Forms.ProgressBar fractalProgressIn)
        {
            if (fractalColorValuesIn.Count < NumberOfColorUsed)
            {
                throw new FractalObserverException("Fractal PythagorasTree needs more colors that are available in the input parameter fractalColorValuesIn!");
            }

            ComputedFractalValues aComputedFractalValuesValues = new ComputedFractalValues();

            for (int aCurrentYPos = 0; aCurrentYPos < yMaxIn; aCurrentYPos++)
            {
                fractalProgressIn.Value = (int)(100.0 * ((double)aCurrentYPos / (double)yMaxIn));

                for (int aCurrentXPos = 0; aCurrentXPos < xMaxIn; aCurrentXPos++)
                {
                    int tempValue = 0;

                    ComplexNumber c = new ComplexNumber();

                    c.Re = fractalRectangleIn.StartX + Math.Abs(fractalRectangleIn.StartX - fractalRectangleIn.EndX) * ((double)aCurrentXPos / (double)xMaxIn);
                    c.Im = fractalRectangleIn.StartY + Math.Abs(fractalRectangleIn.StartY - fractalRectangleIn.EndY) * ((double)aCurrentYPos / (double)yMaxIn);

                    int n = 0;

                    myZValues[n].Re = 0.0;
                    myZValues[n].Im = 0.0;

                    // computation of value for function z2+c, if it converges (if it is bounded) the point is part of mandelbrot set
                    do
                    {
                        n++;

                        myZValues[n] = ComplexOperations.Add(Equation.ComplexFunctionValue(myZValues[n - 1]), c);
                    } while (((Math.Abs(myZValues[n].Re) < myMaximumValueForConvergation) && (Math.Abs(myZValues[n].Im) < myMaximumValueForConvergation)) && (n < (MaximumNumberOfIterations - 1)));

                    tempValue = n;

                    ComputedFractalValue aCFValue = new ComputedFractalValue();

                    FractalColorValue aFractalColorValue = ReturnColor(tempValue, fractalColorValuesIn);
                    aCFValue.ColorValue = aFractalColorValue;
                    aCFValue.AddComputedPoint(new System.Drawing.Point(aCurrentXPos, aCurrentYPos));
                    aCFValue.TypeOfShape = TypesOfShape.Point;
                    aCFValue.UsedTypeOfCoordinateSystem = TypesOfCoordinateSystem.Screen;

                    aComputedFractalValuesValues.AddComputedFractalValue(aCFValue);
                }
            }

            return(aComputedFractalValuesValues);
        }
コード例 #5
0
        private FractalColorValue ReturnColor(int rootIn, int valueIn, IList <FractalColorValue> fractalColorValuesIn)
        {
            FractalColorValue aFractalColorValue = new FractalColorValue();

            // choosing color appropriate to root found
            switch (rootIn)
            {
            case 0:
                aFractalColorValue.red   = fractalColorValuesIn[0].red;
                aFractalColorValue.green = fractalColorValuesIn[0].green;
                aFractalColorValue.blue  = fractalColorValuesIn[0].blue;
                aFractalColorValue.alpha = fractalColorValuesIn[0].alpha;
                break;

            case 1:
                aFractalColorValue.red   = fractalColorValuesIn[1].red;
                aFractalColorValue.green = fractalColorValuesIn[1].green;
                aFractalColorValue.blue  = fractalColorValuesIn[1].blue;
                aFractalColorValue.alpha = fractalColorValuesIn[1].alpha;
                break;

            case 2:
                aFractalColorValue.red   = fractalColorValuesIn[2].red;
                aFractalColorValue.green = fractalColorValuesIn[2].green;
                aFractalColorValue.blue  = fractalColorValuesIn[2].blue;
                aFractalColorValue.alpha = fractalColorValuesIn[2].alpha;
                break;

            case 3:
                aFractalColorValue.red   = fractalColorValuesIn[3].red;
                aFractalColorValue.green = fractalColorValuesIn[3].green;
                aFractalColorValue.blue  = fractalColorValuesIn[3].blue;
                aFractalColorValue.alpha = fractalColorValuesIn[3].alpha;
                break;

            default:
                break;
            }

            // background color is used if too many (maximum) iterations are used to converge to root
            aFractalColorValue = ColorInterpolation.InterpolateColor(valueIn, 0, MaximumNumberOfIterations, aFractalColorValue, fractalColorValuesIn[0]);

            return(aFractalColorValue);
        }
コード例 #6
0
        private FractalColorValue ReadColorFromConfigurationXml(XmlReader xmlReaderIn, string colorNameIn)
        {
            FractalColorValue aFractalColorValue = new FractalColorValue();

            while (xmlReaderIn.Read())
            {
                if (xmlReaderIn.NodeType == XmlNodeType.Element)
                {
                    switch (xmlReaderIn.Name)
                    {
                    case "R":
                    {
                        aFractalColorValue.red = Convert.ToInt32(xmlReaderIn.ReadString(), CultureInfo.InvariantCulture);
                        break;
                    }

                    case "G":
                    {
                        aFractalColorValue.green = Convert.ToInt32(xmlReaderIn.ReadString(), CultureInfo.InvariantCulture);
                        break;
                    }

                    case "B":
                    {
                        aFractalColorValue.blue = Convert.ToInt32(xmlReaderIn.ReadString(), CultureInfo.InvariantCulture);
                        break;
                    }

                    case "A":
                    {
                        aFractalColorValue.alpha = Convert.ToInt32(xmlReaderIn.ReadString(), CultureInfo.InvariantCulture);
                        break;
                    }
                    }
                }
                else if (xmlReaderIn.NodeType == XmlNodeType.EndElement && xmlReaderIn.Name == colorNameIn)
                {
                    break;
                }
            }

            return(aFractalColorValue);
        }
コード例 #7
0
        public ComputedFractalValues ReturnComputedFractalValues(RectangleInPlane fractalRectangleIn, int xMaxIn, int yMaxIn, IList <FractalColorValue> fractalColorValuesIn, System.Windows.Forms.ProgressBar fractalProgressIn)
        {
            if (fractalColorValuesIn.Count < NumberOfColorUsed)
            {
                throw new FractalObserverException("Fractal PythagorasTree needs more colors that are available in the input parameter fractalColorValuesIn!");
            }

            ComputedFractalValues aComputedFractalValues = new ComputedFractalValues();

            aComputedFractalValues.ShallFillInterior = false;

            ComputedFractalValue aCFValue = new ComputedFractalValue();

            FractalColorValue aFractalColorValue = ReturnColor(fractalColorValuesIn);

            aCFValue.ColorValue  = aFractalColorValue;
            aCFValue.TypeOfShape = TypesOfShape.Lines;
            aCFValue.UsedTypeOfCoordinateSystem = TypesOfCoordinateSystem.Plane;

            PointInPlane aStartingPoint = new PointInPlane(myFractalArea.MinX, myFractalArea.MaxY);
            PointInPlane aEndingPoint   = new PointInPlane(myFractalArea.MaxX, myFractalArea.MaxY);

            const int aStartingIteration = 0;

            const double aAngle = Math.PI / 3.0; // angle of -60 degrees - equilateral triangle

            PointInPlane tempPointInPlane = RotateLine(aStartingPoint, aEndingPoint, aAngle);

            CreateNewCurveAndAddItToCFV(aEndingPoint, aStartingPoint, fractalColorValuesIn, ref aCFValue, aStartingIteration);

            CreateNewCurveAndAddItToCFV(aStartingPoint, tempPointInPlane, fractalColorValuesIn, ref aCFValue, aStartingIteration);

            CreateNewCurveAndAddItToCFV(tempPointInPlane, aEndingPoint, fractalColorValuesIn, ref aCFValue, aStartingIteration);

            aComputedFractalValues.AddComputedFractalValue(aCFValue);

            return(aComputedFractalValues);
        }
コード例 #8
0
        // recursive method - here are computed the squares of pythagoras tree
        private void CreateSquare(PointInPlane[] rectanglePointsIn, IList <FractalColorValue> fractalColorValuesIn /*, SquareOrientation squareOrientationIn*/, ref ComputedFractalValues cfvIn, int currentIterationIn)
        {
            if (rectanglePointsIn.Length < 4)
            {
                throw new FractalObserverException("The input parameter rectanglePointsIn in Methode CreateSquare must have at least four values (for each vertex one) !");
            }

            ComputedFractalValue aCFValue = new ComputedFractalValue();

            FractalColorValue aFractalColorValue = ReturnColor(currentIterationIn, fractalColorValuesIn);

            aCFValue.ColorValue  = aFractalColorValue;
            aCFValue.TypeOfShape = TypesOfShape.Rectangle;
            aCFValue.UsedTypeOfCoordinateSystem = TypesOfCoordinateSystem.Plane;

            aCFValue.AddComputedPoint(rectanglePointsIn[0]);
            aCFValue.AddComputedPoint(rectanglePointsIn[1]);
            aCFValue.AddComputedPoint(rectanglePointsIn[2]);
            aCFValue.AddComputedPoint(rectanglePointsIn[3]);

            cfvIn.AddComputedFractalValue(aCFValue);

            if (currentIterationIn < MaximumNumberOfIterations)
            {
                double aScalingCoefficient = 1.0 / Math.Sqrt(2.0);
                double aRotationAngle      = Math.PI / 4.0;

                { // right rectangle values computed
                    PointInPlane[] aNewRightRectangle = new PointInPlane[4];

                    PointInPlane aMovingVector = rectanglePointsIn[2] - rectanglePointsIn[1];

                    // scale to new rectangle
                    aNewRightRectangle[1] = rectanglePointsIn[1];
                    aNewRightRectangle[0] = PointInPlane.ScalePoint(rectanglePointsIn[1], rectanglePointsIn[0], aScalingCoefficient);
                    aNewRightRectangle[2] = PointInPlane.ScalePoint(rectanglePointsIn[1], rectanglePointsIn[2], aScalingCoefficient);
                    aNewRightRectangle[3] = PointInPlane.ScalePoint(rectanglePointsIn[1], rectanglePointsIn[3], aScalingCoefficient);

                    // rotate to new rectangle
                    aNewRightRectangle[0] = PointInPlane.RotatePoint(aNewRightRectangle[0], aNewRightRectangle[1], aRotationAngle);
                    aNewRightRectangle[1] = PointInPlane.RotatePoint(aNewRightRectangle[1], aNewRightRectangle[1], aRotationAngle);
                    aNewRightRectangle[2] = PointInPlane.RotatePoint(aNewRightRectangle[2], aNewRightRectangle[1], aRotationAngle);
                    aNewRightRectangle[3] = PointInPlane.RotatePoint(aNewRightRectangle[3], aNewRightRectangle[1], aRotationAngle);

                    // move to new rectangle position
                    aNewRightRectangle[0] = PointInPlane.MovePoint(aNewRightRectangle[0], aMovingVector);
                    aNewRightRectangle[1] = PointInPlane.MovePoint(aNewRightRectangle[1], aMovingVector);
                    aNewRightRectangle[2] = PointInPlane.MovePoint(aNewRightRectangle[2], aMovingVector);
                    aNewRightRectangle[3] = PointInPlane.MovePoint(aNewRightRectangle[3], aMovingVector);

                    CreateSquare(aNewRightRectangle, fractalColorValuesIn, ref cfvIn, currentIterationIn + 1);
                }

                { // left rectangle values computed
                    aRotationAngle = -Math.PI / 4.0;

                    PointInPlane[] aNewLeftRectangle = new PointInPlane[4];

                    PointInPlane aMovingVector = rectanglePointsIn[3] - rectanglePointsIn[0];

                    // scale to new rectangle
                    aNewLeftRectangle[0] = rectanglePointsIn[0];
                    aNewLeftRectangle[1] = PointInPlane.ScalePoint(rectanglePointsIn[0], rectanglePointsIn[1], aScalingCoefficient);
                    aNewLeftRectangle[2] = PointInPlane.ScalePoint(rectanglePointsIn[0], rectanglePointsIn[2], aScalingCoefficient);
                    aNewLeftRectangle[3] = PointInPlane.ScalePoint(rectanglePointsIn[0], rectanglePointsIn[3], aScalingCoefficient);

                    // rotate to new rectangle
                    aNewLeftRectangle[0] = PointInPlane.RotatePoint(aNewLeftRectangle[0], aNewLeftRectangle[0], aRotationAngle);
                    aNewLeftRectangle[1] = PointInPlane.RotatePoint(aNewLeftRectangle[1], aNewLeftRectangle[0], aRotationAngle);
                    aNewLeftRectangle[2] = PointInPlane.RotatePoint(aNewLeftRectangle[2], aNewLeftRectangle[0], aRotationAngle);
                    aNewLeftRectangle[3] = PointInPlane.RotatePoint(aNewLeftRectangle[3], aNewLeftRectangle[0], aRotationAngle);

                    // move to new rectangle position
                    aNewLeftRectangle[0] = PointInPlane.MovePoint(aNewLeftRectangle[0], aMovingVector);
                    aNewLeftRectangle[1] = PointInPlane.MovePoint(aNewLeftRectangle[1], aMovingVector);
                    aNewLeftRectangle[2] = PointInPlane.MovePoint(aNewLeftRectangle[2], aMovingVector);
                    aNewLeftRectangle[3] = PointInPlane.MovePoint(aNewLeftRectangle[3], aMovingVector);

                    CreateSquare(aNewLeftRectangle, fractalColorValuesIn, ref cfvIn, currentIterationIn + 1);
                }
            }
        }
コード例 #9
0
        public static FractalColorValue InterpolateColor(int valueIn, int minimumValueIn, int maximumValueIn, FractalColorValue color1In, FractalColorValue color2In)
        {
            FractalColorValue aInterpolatedColor;

            aInterpolatedColor = InterpolateColor((double)valueIn, (double)minimumValueIn, (double)maximumValueIn, color1In, color2In);

            return(aInterpolatedColor);
        }
コード例 #10
0
        private FractalColorValue ReturnColor(IList <FractalColorValue> fractalColorValuesIn)
        {
            FractalColorValue aFractalColorValue = fractalColorValuesIn[1];

            return(aFractalColorValue);
        }