Mandelbrot set

You are encouraged to solve this task according to the task description, using any language you may know.


Task

Generate and draw the Mandelbrot set.



Note that there are many algorithms to draw Mandelbrot set and there are many functions which generate it .




 
PRO Mandelbrot,xRange,yRange,xPixels,yPixels,iterations
 
xPixelstartVec = Lindgen( xPixels) * Float(xRange[1]-xRange[0]) / $
                 xPixels + xRange[0]
yPixelstartVec = Lindgen( yPixels) * Float(YRANGE[1]-yrange[0])$
                 / yPixels + yRange[0]
 
constArr = Complex( Rebin( xPixelstartVec, xPixels, yPixels),$
                     Rebin( Transpose(yPixelstartVec), xPixels, yPixels))
 
valArr = ComplexArr( xPixels, yPixels)
 
res = IntArr( xPixels, yPixels)
 
oriIndex = Lindgen( Long(xPixels) * yPixels)
 
FOR i = 0, iterations-1 DO BEGIN ; only one loop needed
 
    ; calculation for whole array at once
    valArr = valArr^2 - constArr
 
    whereIn = Where( Abs( valArr) LE 4.0d, COMPLEMENT=whereOut)
 
    IF whereIn[0] EQ -1 THEN BREAK
 
    valArr = valArr[ whereIn]
 
    constArr = constArr[ whereIn]
 
    IF whereOut[0] NE -1 THEN BEGIN
 
        res[ oriIndex[ whereOut]] = i+1
 
        oriIndex = oriIndex[ whereIn]
    ENDIF
ENDFOR
 
tv,res ; open a window and show the result
 
END
 
 
Mandelbrot,[-1.,2.3],[-1.3,1.3],640,512,200
 
END
 
 