Ejemplo n.º 1
0
        public void Mul(ImgNumber num)
        {
            double newRe  = Re * num.Re - Img * num.Img;
            double newImg = Re * num.Img + Img * num.Re;

            this.Re  = newRe;
            this.Img = newImg;
        }
Ejemplo n.º 2
0
        private int GetExit(ImgNumber start, ImgNumber c, int iterations)
        {
            for (int i = 0; i < iterations; i++)
            {
                if (start.Length() > 2)
                {
                    return(i);
                }

                start.Mul(start);
                start.Add(c);
            }

            return(-1);
        }
Ejemplo n.º 3
0
        public void CalculateJulia(ImgNumber z)
        {
            double zoom = (double)numericUpDown_zoom.Value;

            double xMin = 0 - zoom + (double)numericUpDown_xOffset.Value;
            double xMax = 0 + zoom + (double)numericUpDown_xOffset.Value;

            double yMin = 0 - zoom - (double)numericUpDown_yOffset.Value;
            double yMax = 0 + zoom - (double)numericUpDown_yOffset.Value;

            int maxIterations = (int)numericUpDown_Iterations.Value;

            for (int i = 0; i < canvase.Width; i++)
            {
                for (int j = 0; j < canvase.Height; j++)
                {
                    double re  = map(i, 0, canvase.Width, xMin, xMax);
                    double img = map(j, 0, canvase.Height, yMin, yMax);

                    ImgNumber c = new ImgNumber(re, img);

                    //int it = GetExit(new ImgNumber(), c, maxIterations);
                    int it = GetExit(c, z, maxIterations);

                    Color pixelColor = new Color();

                    if (it == -1)
                    {
                        pixelColor = Color.Black;
                    }
                    else if (it == 1)
                    {
                        pixelColor = Color.Gray;
                    }
                    else
                    {
                        int colorGrad = (int)map(it, 0, maxIterations, 30, 255);
                        pixelColor = Color.FromArgb(colorGrad, colorGrad, colorGrad);
                    }

                    canvase.SetPixel(i, j, pixelColor);
                }
            }
            this.pictureBox1.Image = canvase;
        }
Ejemplo n.º 4
0
        public void CalculateMandelbrot()
        {
            double zoom = (double)numericUpDown_zoom.Value;

            double xMin = 0 - zoom + (double)numericUpDown_xOffset.Value;
            double xMax = 0 + zoom + (double)numericUpDown_xOffset.Value;

            double yMin = 0 - zoom - (double)numericUpDown_yOffset.Value;
            double yMax = 0 + zoom - (double)numericUpDown_yOffset.Value;

            int maxIterations = (int)numericUpDown_Iterations.Value;

            for (int i = 0; i < canvase.Width; i++)
            {
                for (int j = 0; j < canvase.Height; j++)
                {
                    double re  = map(i, 0, canvase.Width, xMin, xMax);
                    double img = map(j, 0, canvase.Height, yMin, yMax);

                    /*
                     * if ((re < 1.01 && re > 0.99) && ((re < 0.01 && re > -0.01) || (img < 0.01 && img > -0.01)) ||
                     *  (re > -1.01 && re < -0.99) && ((re < 0.01 && re > -0.01) || (img < 0.01 && img > -0.01)) ||
                     *  (img > -1.01 && img < -0.99) && ((re < 0.01 && re > -0.01) || (img < 0.01 && img > -0.01)) ||
                     *  (img < 1.01 && img > 0.99) && ((re < 0.01 && re > -0.01) || (img < 0.01 && img > -0.01)))
                     * {
                     *  canvase.SetPixel(i, j, Color.Blue);
                     *  continue;
                     * }
                     * else if ((re < 0.01 && re > -0.01) || (img < 0.01 && img > -0.01))
                     * {
                     *  canvase.SetPixel(i, j, Color.Red);
                     *  continue;
                     * }
                     */

                    ImgNumber c = new ImgNumber(re, img);

                    int it = GetExit(new ImgNumber(), c, maxIterations);
                    //int it = GetExit(c, new ImgNumber(0, -1), maxIterations);



                    Color pixelColor = new Color();

                    if (it == -1)
                    {
                        pixelColor = Color.Black;
                    }
                    else if (it == 1)
                    {
                        pixelColor = Color.Gray;
                    }
                    else
                    {
                        int colorGrad = (int)map(it, 0, maxIterations, 30, 255);
                        pixelColor = Color.FromArgb(colorGrad, colorGrad, colorGrad);
                    }

                    canvase.SetPixel(i, j, pixelColor);
                }
            }
            this.pictureBox1.Image = canvase;
        }
Ejemplo n.º 5
0
 public void Sub(ImgNumber num)
 {
     Re  = Re - num.Re;
     Img = Img - num.Img;
 }
Ejemplo n.º 6
0
 public void Add(ImgNumber num)
 {
     Re  = Re + num.Re;
     Img = Img + num.Img;
 }
Ejemplo n.º 7
0
 public ImgNumber(ImgNumber num)
 {
     this.Re  = num.Re;
     this.Img = num.Img;
 }