C# Mandelbrot分形不工作

C# Mandelbrot分形不工作,c#,.net,fractals,C#,.net,Fractals,我试着制作这个Mandelbrot分形发生器,但当我运行它时,我得到了一个像圆一样的输出。 不知道为什么会这样。我想我的颜色可能有问题,但即使如此,形状也不正确 public static Bitmap Generate( int width, int height, double realMin, double realMax, double imaginaryMin, double imagina

我试着制作这个Mandelbrot分形发生器,但当我运行它时,我得到了一个像圆一样的输出。 不知道为什么会这样。我想我的颜色可能有问题,但即使如此,形状也不正确

public static Bitmap Generate(
        int width,
        int height,
        double realMin,
        double realMax,
        double imaginaryMin,
        double imaginaryMax,
        int maxIterations,
        int bound)
    {
        var bitmap = new FastBitmap(width, height);
        var planeWidth = Math.Abs(realMin) + Math.Abs(realMax); // Total width of the plane.
        var planeHeight = Math.Abs(imaginaryMin) + Math.Abs(imaginaryMax); // Total height of the plane.
        var realStep = planeWidth / width; // Amount to step by on the real axis per pixel.
        var imaginaryStep = planeHeight / height; // Amount to step by on the imaginary axis per pixel.
        var realScaling = width / planeWidth;
        var imaginaryScaling = height / planeHeight;
        var boundSquared = bound ^ 2;
        for (var real = realMin; real <= realMax; real += realStep) // Loop through the real axis.
        {
            for (var imaginary = imaginaryMin; imaginary <= imaginaryMax; imaginary += imaginaryStep) // Loop through the imaginary axis.
            {
                var z = Complex.Zero;
                var c = new Complex(real, imaginary);
                var iterations = 0;
                for (; iterations < maxIterations; iterations++)
                {
                    z = z * z + c;
                    if (z.Real * z.Real + z.Imaginary * z.Imaginary > boundSquared)
                    {
                        break;
                    }
                }
                if (iterations == maxIterations)
                {
                    bitmap.SetPixel(
                        (int)((real + Math.Abs(realMin)) * realScaling),
                        (int)((imaginary + Math.Abs(imaginaryMin)) * imaginaryScaling),
                        Color.Black);
                }
                else
                {
                    var nsmooth = iterations + 1 - Math.Log(Math.Log(Complex.Abs(z))) / Math.Log(2);
                    var color = MathHelper.HsvToRgb(0.95f + 10 * nsmooth, 0.6, 1.0);
                    bitmap.SetPixel(
                        (int)((real + Math.Abs(realMin)) * realScaling),
                        (int)((imaginary + Math.Abs(imaginaryMin)) * imaginaryScaling),
                        color);
                }
            }
        }
        return bitmap.Bitmap;
    }
公共静态位图生成(
整数宽度,
整数高度,
双realMin,
双realMax,
双重想象,
双重想象Max,
int最大迭代次数,
整数范围)
{
var位图=新的快速位图(宽度、高度);
var planeWidth=Math.Abs(realMin)+Math.Abs(realMax);//平面的总宽度。
var planeHeight=Math.Abs(imaginaryMin)+Math.Abs(imaginaryMax);//平面的总高度。
var realStep=planeWidth/width;//每像素在实轴上的步进量。
var imaginaryStep=planeHeight/height;//每像素在假想轴上的步进量。
var realScaling=宽度/平面宽度;
var ImageAryScaling=高度/平面高度;
var boundSquared=绑定^2;
对于(var real=realMin;real,这里有一个错误:

var boundSquared = bound ^ 2;
这应该是:

var boundSquared = bound * bound;
^
运算符表示
xor

这里有一个错误:

var boundSquared = bound ^ 2;
这应该是:

var boundSquared = bound * bound;
^
运算符表示
xor

这里有一个错误:

var boundSquared = bound ^ 2;
这应该是:

var boundSquared = bound * bound;
^
运算符表示
xor

这里有一个错误:

var boundSquared = bound ^ 2;
这应该是:

var boundSquared = bound * bound;

^
操作符的意思是
xor

哇。我不敢相信这样一个简单的小错误会毁掉整个事情。这解决了它。虽然我仍然有着色问题。着色是一个不同的问题(有它自己的主题)。但是当你能画黑白曼德布罗特时,你就少了一个问题:-)哇。我真不敢相信这样一个简单的小错误会毁掉整个事情。这就解决了它。虽然我仍然有着色问题。着色是一个不同的问题(有自己的主题)但是当你能画出黑白的Mandelbrot时,你就少了一个问题:-)哇,我不敢相信这样一个简单的小错误会毁掉整件事。这就解决了它。虽然我仍然有着色问题。着色是一个不同的问题(有它自己的主题)但是当你能画出黑白的Mandelbrot时,你就少了一个问题:-)哇,我不敢相信这样一个简单的小错误会毁掉整件事。这就解决了它。虽然我仍然有着色问题。着色是一个不同的问题(有它自己的主题).但当你能画出黑白的曼德尔布罗特时,你就少了一个问题:-)