I'm trying to implement a very basic fractal (the Mandelbrot set) generator, and from looking on the internet I've come to the conclusion that this is the correct code. However, all I am left with is a black image, with a few pixels in the top left corner that are white. I've written my own Complex Number class, and proved it works, so I don't think it's worth posting on here (but correct me if I'm wrong).
Anyway, this is the code to generate a Bitmap:
public Bitmap CalculateFractal()
{
Bitmap bImage = new Bitmap(640, 480);
int nMaxIterations = 100;
for (int y = 0; y < bImage.Height; y++)
{
for (int x = 0; x < bImage.Width; x++)
{
ComplexNumber Z = new ComplexNumber(0, 0);
ComplexNumber C = new ComplexNumber(x, y);
if (x == 5 && y == 5)
{
;
}
int nCount = 0;
for (nCount = 0; Z.Modulus <= 2.0m && nCount < nMaxIterations; nCount++)
{
Z = (Z * Z) + C;
}
if (nCount < nMaxIterations)
{
bImage.SetPixel(x, y, Color.Black);
}
else
{
bImage.SetPixel(x, y, Color.White);
}
}
}
return bImage;
}
Any help is appreciated! I realise this is more of a maths question than C#, as I understand the code part!
Thanks,
Thomas.


Sign In
Create Account

Back to top









