コード例 #1
0
        public void GenerateSet()
        {
            try
            {
                this.ZExponent = Convert.ToInt32(this.ZExpTB.Text);
                this.CExponent = Convert.ToInt32(this.CExpTB.Text);

                RenderProgress.Minimum = 0;
                RenderProgress.Maximum = 1045;

                this.width  = ClientRectangle.Width;
                this.height = ClientRectangle.Height;

                this.ZoomScale = Convert.ToDouble(this.zoom.Text);
                if (Convert.ToInt32(IterationsTB.Text) > 255)
                {
                    this.IterationsTB.Text = "255";
                    this.MaxIter           = 255;
                }
                else if (Convert.ToInt32(IterationsTB.Text) < 0)
                {
                    this.IterationsTB.Text = "255";
                    this.MaxIter           = 255;
                }
                else
                {
                    this.MaxIter = Convert.ToInt32(IterationsTB.Text);
                }


                GraphicsObject.Clear(Color.Black);
                Refresh();

                Color  thisColour = Color.Blue;
                Color  lastColour = Color.Red;
                double Normalized = 0;

                XDisposition = Convert.ToDouble(XDispTB.Text);
                YDisposition = Convert.ToDouble(YDispTB.Text);

                CValue.Real      = Convert.ToDouble(CRealTb.Text);
                CValue.Imaginary = Convert.ToDouble(CImagTb.Text);

                Color last = Color.Red;

                int line  = 0;
                int iLast = 0;

                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        ZValue.Real      = 1.5 * (x - width - 1 / 2) / (0.5 * ZoomScale * width) + XDisposition;
                        ZValue.Imaginary = 1.0 * (y - height - 1 / 2) / (0.5 * ZoomScale * height) + YDisposition;


                        int i = 0;
                        if (this.ZExponent == 2 && this.CExponent == 0)
                        {
                            do
                            {
                                ZValue     = ComplexMath.SquarePlus(ZValue, CValue);
                                Normalized = ComplexMath.SquareModulus(ZValue);
                                i++;
                            } while (Normalized < 4.0 && i < MaxIter);
                        }

                        else if (this.ZExponent != 2 && this.CExponent == 0)
                        {
                            do
                            {
                                ZValue     = ComplexMath.PowerPlusConst(ZValue, ZExponent, CValue);
                                Normalized = ComplexMath.SquareModulus(ZValue);
                                i++;
                            } while (Normalized < 4.0 && i < MaxIter);
                        }
                        else
                        {
                            do
                            {
                                ZValue     = ComplexMath.PowerPlusConst(ZValue, ZExponent, ComplexMath.Power(CValue, CExponent));
                                Normalized = ComplexMath.SquareModulus(ZValue);
                                i++;
                            } while (Normalized < 4.0 && i < MaxIter);
                        }
                        Color col;
                        if (i == iLast)
                        {
                            col = last;
                        }
                        else
                        {
                            col = Colours[i];
                        }
                        Canvas.SetPixel(x, y, col);
                    }
                    line++;
                    if (line % 120 == 0)
                    {
                        RenderProgress.Value = line;
                        Refresh();
                    }
                }

                RenderProgress.Value = line;

                Refresh();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
コード例 #2
0
        public static Tuple <int, double> GetEscapeIterations(int ZExponent, int CExponent, ComplexNumber ZComplex, ComplexNumber CComplex, int MaximumIterations)
        {
            int    Iterations = 0;
            double Normalized = 0.0;

            ExponentStates state;

            if (ZExponent == 2 && CExponent == 0)
            {
                state = ExponentStates.DEFAULT_EXPONENT_VALUES;
            }
            else if (ZExponent != 2 && CExponent == 0)
            {
                state = ExponentStates.NON_DEFAULT_Z_EXPONENT;
            }
            else
            {
                state = ExponentStates.ANY_OTHER_CASE;
            }

            switch (state)
            {
            case ExponentStates.DEFAULT_EXPONENT_VALUES:
                do
                {
                    ZComplex   = ComplexMath.SquarePlus(ZComplex, CComplex);
                    Normalized = ComplexMath.SquareModulus(ZComplex);
                    Iterations++;
                } while ((Normalized <= (4)) && (Iterations < MaximumIterations));

                break;

            case ExponentStates.NON_DEFAULT_Z_EXPONENT:

                do
                {
                    ZComplex   = ComplexMath.PowerPlusConst(ZComplex, ZExponent, CComplex);
                    Normalized = ComplexMath.SquareModulus(ZComplex);
                    Iterations++;
                } while ((Normalized <= (4)) && (Iterations < MaximumIterations));

                break;

            case ExponentStates.ANY_OTHER_CASE:

                do
                {
                    ZComplex   = ComplexMath.PowerPlusConst(ZComplex, ZExponent, ComplexMath.Power(CComplex, CExponent));
                    Normalized = ComplexMath.SquareModulus(ZComplex);
                    Iterations++;
                } while ((Normalized <= (4)) && (Iterations < MaximumIterations));

                break;

            default:
                MessageBox.Show("Default Case, No Proper Values inputted");

                break;
            }
            return(new Tuple <int, double>(Iterations, Normalized));
        }