예제 #1
0
        private void Plot(int w, int h)
        {
            _ = Parallel.For(0, w, x =>
            {
                for (int y = 0; y < h; y++)
                {
                    double r  = domain[x, y, 0];
                    double i  = domain[x, y, 1];
                    double rx = Auxiliary.Random();
                    double ry = Auxiliary.Random();
                    r        += rx;
                    i        += ry;

                    if (Iterate(r, i, w, h, false))
                    {
                        Iterate(r, i, w, h, true);
                    }
                }
            });
        }
예제 #2
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MyForm(settings, fractals, shaders));

            pixels = new int[settings.Width * settings.Height];
            domain = new double[settings.Width, settings.Height, 2];

            for (int x = 0; x < settings.Width; x++)
            {
                double mx = Auxiliary.MapDouble(x, 0, settings.Width, -2 * settings.AspectRatio, 2 * settings.AspectRatio);
                for (int y = 0; y < settings.Height; y++)
                {
                    double my = Auxiliary.MapDouble(y, 0, settings.Height, -2, 2);
                    domain[x, y, 0] = mx;
                    domain[x, y, 1] = my;
                }
            }
        }
예제 #3
0
        //Iterate the Mandelbrot and return TRUE if the point escapes
        //Also handle the drawing of the exit points
        private bool Iterate(double x0, double y0, int w, int h, bool drawIt)
        {
            double x = 0;
            double y = 0;
            double xnew, ynew;

            for (int i = 0; i < properties.Bailout; i++)
            {
                ynew = (x * x - y * y) + x0;
                xnew = (2 * x * y) + y0;

                if (drawIt && (i > properties.Cutoff))
                {
                    int ix = (int)Auxiliary.MapDouble(xnew, domain[0, 0, 0], domain[w - 1, 0, 0], 0, w - 1);
                    int iy = (int)Auxiliary.MapDouble(ynew, domain[0, 0, 1], domain[0, h - 1, 1], 0, h - 1);

                    if (ix >= 0 && iy >= 0 && iy < h && ix < w)
                    {
                        // rotate and expose point
                        int index = iy * w + ix;
                        pixels[index]++;
                        if (highest < pixels[index])
                        {
                            highest = pixels[index];
                        }
                    }
                }
                if ((xnew * xnew + ynew * ynew) > 4)
                {
                    // escapes
                    return(true);
                }
                y = xnew;
                x = ynew;
            }
            //does not escape

            return(false);
        }
예제 #4
0
        //Returns an array of values between 0 and 1.
        //public static double[] NormalizeArray(int[] exposure, double[] normalized)
        //{

        //    int min = int.MaxValue;
        //    int max = 0;

        //    Parallel.For(0, exposure.Length, i =>
        //    {
        //        if (exposure[i] < min) { min = exposure[i]; }
        //        if (exposure[i] > max) { max = exposure[i]; }
        //    });

        //    _ = Parallel.For(0, exposure.Length, i =>
        //    {
        //        double norm = Auxiliary.Normalize(exposure[i], min, max);
        //        normalized[i] = norm;

        //    });
        //    return normalized;
        //}
        //INPUT: An array of doubles
        //OUTPUT: An array of doubles normalized between 0 and 1
        public static double[] NormalizeArray(double[] arr)
        {
            double[] norm_arr = new double[arr.Length];
            double   min      = 99999;
            double   max      = 0;

            Parallel.For(0, arr.Length, i =>
            {
                if (arr[i] < min)
                {
                    min = arr[i]; Console.WriteLine("min: " + min);
                }
                if (arr[i] > max)
                {
                    max = arr[i]; Console.WriteLine("max: " + max);
                }
            });
            _ = Parallel.For(0, norm_arr.Length, i =>
            {
                double norm = Auxiliary.Normalize(arr[i], min, max);
                norm_arr[i] = norm;
            });
            return(norm_arr);
        }