Mandelbrot set

Apply the complex function/transform \displaystyle{ z \to z^2+c}, with z initially 0, many times – say 500 – to each point c in an area near 0. In terms of the Cartesian plane,

    \begin{align*} x &\to x^2-y^2+x_c \\ y &\to 2xy+y_c \end{align*}

Test, by measuring the distance \sqrt{x^2+y^2}, if the point is escaping to \infty or staying near 0. Maybe if distance >10, assume it’s escaping; colour it white, otherwise colour it black. Voila, the basic Mandelbrot set diagram:

[b&w M picture]

PROGRAM: Mandelbrot set
Ws, Hs = width, height of screen in pixels
Wr, Hr = actual width, height of desired visual field
Cx, Cy = centre of area to display (initially 0,0 usually)
LIMIT = 5 //Fairly arbitrary value to test for escape
Xinc = Wr/Ws //actual width represented by one pixel 
Yinc = Hr/Hs
XLeft = Cx - Wr/2
XRight = Cx + Wr/2
YBottom = Cy - Hr/2
YTop = Cy + Hr/2
for xc=XLeft to XRight step Xinc
    for yc=YBottom to YTop step Yinc
        x=0 
        y=0
        for i=1 to 500
            xtemp=x*x-y*y+xc
            y=2*x*y+yc
            x=xtemp
            if (x*x+y*y)>LIMIT break //quit i loop
        end i
        Draw(xc,yc,i)
    end yc
end xc


The value of i is used for colouring the pixel.

Questions
Q. Testing for x^2+y^2, not \sqrt{x^2+y^2}, like the program does here, and I usually do, because it’s faster, is different to the proper sqrt-distance. How different?
Q. There are many different ways of colouring the points besides just i. Like what.
Q. Using i discards all information except final distance from 0. How about direction, total distance travelled, x- and y-distance, how close to path got to an axis (Pickover stalks) etc etc etc.

Leave a Reply

Your email address will not be published. Required fields are marked *