To code the

mandelbrot set, make two

nested loops

ilterating from r = -1 to 1 and i = -1 to 1 by small

increments, say 0.005. Map each (r,i)

coordinate to a

pixel (x,y) on the

screen.

Let z be a complex number. Then, for each pixel, count how many times you can square z and add (r,i) to make a new z, before z's absolute value is larger than e.g. 2. Make sure to put an upper bound on this loop, because for some combinations of (r,i), z's absolute value never rises above 2.

Use these formulas:

z_{r} = z_{r}^{2} - z_{i}^{2} + r

z_{i} = 2z_{r}z_{i} + i

Make sure you use the *old* z_{r} in the second formula, and not the one you just calculated.

Now, pick the color of the pixel in question based on how many times the loop ilterated, and put it on the screen. Make the color black if your loop hit the upper bound.

Voila! After waiting a bit, you'll have a beautiful mandelbrot fractal on your screen.