



The Mandelbrot set in Excel Visual Basic

A point in the complex plane belongs to the Mandelbrot set if the orbit of 0 under interation of the quadratic map:

z n =z2 n+1

remains bounded (does not escape to infinity).



It can be plotted on a square image between -2-2i and 2+2i.



For practical reasons, we'll only iterate 255 times for each point. We will only iterate a given point as long as the absolute value of z n is lower than 2. If it's 2 or greater, we know it will eventually escape to infinity, so we don't have to continue the iterations. The number of iterations determines the point's color.





z n =z2 n+1

[Do Until (i = 255)]

[(zx * zx + zy * zy) >= 4]

For y = 1 To 200 For x = 1 To 200 i = 0 zx = 0 zy = 0 cx = -2 + x / 50 cy = -2 + y / 50 Do Until (i = 255) Or (zx * zx + zy * zy) >= 4 xt = zx * zy zx = zx * zx - zy * zy + cx zy = 2 * xt + cy i = i + 1 Loop Cells(y, x).Interior.Color = VBA.RGB(10, 10, i * 10) Next x Next y

For beginners

cx = -2 + x / 50 cy = -2 + y / 50

cx = -0.68 + x / 1200 cy = -0.74 + y / 1200

variables:



i - number of iterations

x,y - screen coordinates (row and column) of the point currently being iterated. (0,0) is in the upper left corner; (200,200) in the bottom right.

cx,cy - coordinates of the point currently being iterated, on the complex plane - corresponding to x and y.(-2,-2) is in the bottom left corner; (2,2) in the upper right.



