예제 #1
0
        public Bitmap mandelBrotFractalBMP()
        {
            Bitmap returnBMP = new Bitmap(width, height);

            LockBitmap lockBitmap = new LockBitmap(returnBMP);

            lockBitmap.LockBits();

            double minX = centerX - zoomScale / 2;
            double minY = centerY - zoomScale / 2;

            Parallel.For(0, width, (x) =>
            {
                Parallel.For(0, height, (y) =>
                {
                    double a = minX + (double)x / width * zoomScale;
                    double b = minY + (double)y / height * zoomScale;

                    ComplexPoint C = new ComplexPoint(a, b);
                    ComplexPoint Z = new ComplexPoint(0, 0);

                    int iterations = 0;
                    for (iterations = 0; iterations < max; iterations++)
                    {
                        Z = Z * Z;
                        Z = Z + C;

                        double magnitude = ComplexPoint.Abs(Z);

                        if (magnitude > 2.0)
                        {
                            break;
                        }
                    }

                    if (iterations < max)
                    {
                        lockBitmap.SetPixel(x, y, colorArray.GetColor(iterations));
                    }
                    else
                    {
                        lockBitmap.SetPixel(x, y, System.Drawing.Color.Black);
                    }
                });
            });

            lockBitmap.UnlockBits();

            mandelBrotBMP = returnBMP;
            return(returnBMP);
        }
예제 #2
0
        public static double Abs(ComplexPoint value)
        {
            double c = Math.Abs(value.R);
            double d = Math.Abs(value.Im);

            if (c > d)
            {
                double r = d / c;
                return(c * Math.Sqrt(1.0 + r * r));
            }
            else if (d == 0.0)
            {
                return(c);  // c is either 0.0 or NaN
            }
            else
            {
                double r = c / d;
                return(d * Math.Sqrt(1.0 + r * r));
            }
        }