I am new to coding and I have started my journey by learning C# as my first programming language. As an assigment I am trying to code a program that draws a Mandelbrot set, but it is not drawing what it is supposed to and I can't seem to find any issues whilst debugging. It just draws a white square with a few black pixels in the top left.
Here is the most important part of my code (PaintEventArgs method):
//Magnitude and mandelnum @ start
int mandelnum = 0;
double Magnitude = 0; //Magnitude is the distance of (a,b) to middle of my picturebox
//a and b @ start. a and b are all (x,y) pixels of my bitmap reformed with the
following formulas: (a*a-b*b+x, 2*a*b+y)
double a = 0;
double b = 0;
int x = 0;
int y = 0;
int picboxmiddleX = (50 + pictureBox1.Width) / 2;
int picboxmiddleY = (110 + pictureBox1.Height) / 2; //the location of picturebox is
(50,110)
//loop through all pixels, calc magnitude for every (x,y) and stop if magnitude is
larger than 2, attach color black or white to ever pixel dependent on even or odd
mandelnums.
for (x = 0; x < pictureBox1.Width; x++)
{
for (y = 0; y < pictureBox1.Height; y++)
{
while (Magnitude < 2.0) {
mandelgetal++;
if (mandelgetal < 100)
{
break;
}
a = (a * a) - (b * b) + x;
b = (2 * a * b) + y;
Magnitude = Math.Sqrt(Math.Pow((a - middenpanelX), 2) + Math.Pow((b -
middenpanelY), 2));
}
//pixels with even mandelnum get color white and odd is black
if (mandelgetal % 2 == 0)
{
bm.SetPixel(x, y, Color.White);
}
else if (mandelgetal % 2 != 0)
{
bm.SetPixel(x, y, Color.Black);
}
}
}
pictureBox1.Image = bm;
}
I hope someone can help!

Looks to me like it stops calculating as soon as
Magnitudegoes above/equalto 2.0 - nothing seems to reset it to below that..As the calcs for pixel values are done in the
whileloop, if thewhileloop doesn't run then your pixels will all be white or black depending on what valuemandelgetaljammed at..If you're getting a few black pixels in the top left*, then it seems reasonable to say the
whileloop runs some small number of times, but then doesn't after (say) 10 pixels, and the rest of the thousands of pixels in the PB are just painted the same color*in winforms the origin 0,0 is in the top left