Example #1
0
        public override int[,] calculate(FractalPart fa)
        {
            int w;
            //set max pixel value range from 0-255
            int w_max = 255;

            int[,] pixels = new int[fa.getWidth(), fa.getHeight()];

            double dx = (fa.x2 - fa.x1) / fa.getWidth();
            double dy = (fa.y2 - fa.y1) / fa.getHeight();

            double cr, ci, zr, zi, zr2, zi2, zrt;

            // For every pixel width x height of this FractalPart
            for (int Xcount = 0; Xcount < fa.getWidth(); Xcount++)
            {
                for (int Ycount = 0; Ycount < fa.getHeight(); Ycount++)
                {
                    cr = fa.x1 + dx * Xcount;
                    ci = fa.y1 + dy * Ycount;

                    w   = 0;
                    zr  = 0;
                    zi  = 0;
                    zr2 = 0;
                    zi2 = 0;

                    // Calculate fractal
                    while (((zr2 + zi2) < 4) && (w < w_max))
                    {
                        zrt = zr2 - zi2 + cr;
                        zi  = 2 * zr * zi + ci;
                        zr  = zrt;
                        zr2 = Math.Pow(zr, 2);
                        zi2 = Math.Pow(zi, 2);
                        w++;
                    }
                    pixels[Xcount, Ycount] = (w < w_max) ? w : w_max;
                }
            }
            return(pixels);
        }
Example #2
0
        public override int[,] calculate(FractalPart fa)
        {
            int w;
            //Max pixel value range 0-255
            int w_max = 255;

            int[,] pixels = new int[fa.getWidth(), fa.getHeight()];

            //real and imaginary part of the constant c, determinate shape of the Julia Set
            double cX, cY;
            double zx, zy;

            // The JuliaSet requires a Constant to draw wheras the MandleBrot recalculates this value.
            cX = -0.7;
            cY = -0.27015;

            // Loop through each
            for (int Xcount = 0; Xcount < fa.getWidth(); Xcount++)
            {
                for (int Ycount = 0; Ycount < fa.getHeight(); Ycount++)
                {
                    w = 0;

                    // Sets the actual value.
                    zx = (fa.x2 - fa.x1) * (Xcount - fa.getWidth() / 2) / (0.5 * fa.getWidth());
                    zy = (fa.y2 - fa.y1) * (Ycount - fa.getHeight() / 2) / (0.5 * fa.getHeight());

                    // Calculate w to fill in the pixels.
                    while (zx * zx + (zy * zy) < 4 && w < w_max)
                    {
                        double tmp = zx * zx - zy * zy + cX;
                        zy = 2.0 * zx * zy + cY;
                        zx = tmp;
                        w++;
                    }
                    pixels[Xcount, Ycount] = (w < w_max) ? w : w_max;
                }
            }

            return(pixels);
        }