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 .




 _2.1 sx # xmin = -2.1
  0.7 sX # xmax =  0.7
 
 _1.2 sy # ymin = -1.2
  1.2 sY # ymax =  1.2
 
   32 sM # maxiter = 32
 
   80 sW # image width
   25 sH # image height
 
    8 k  # precision
 
[ q ] sq # quitter helper macro
 
# for h from 0 to H-1
0 sh
[
  lh lH =q # quit if H reached
 
  # for w from 0 to W-1
  0 sw
  [
    lw lW =q # quit if W reached
 
    # (w,h) -> (R,I)
    #           | |
    #           | ymin + h*(ymax-ymin)/(height-1)
    #           xmin + w*(xmax-xmin)/(width-1)
 
    lX lx - lW 1 - / lw * lx + sR
    lY ly - lH 1 - / lh * ly + sI
 
    # iterate for (R,I)
 
    0 sr #     r:=0
    0 si #     i:=0
    0 sa #     a:=0 (r squared)
    0 sb #     b:=0 (i squared)
    0 sm #     m:=0
 
    # do while m!=M and a+b=<4
    [
      lm lM =q # exit if m==M
      la lb + 4<q # exit if >4
 
      2 lr * li * lI + si # i:=2*r*i+I
      la lb - lR + sr     # r:=a-b+R
      lm 1 + sm           # m+=1
      lr 2 ^ sa           # a:=r*r
      li 2 ^ sb           # b:=i*i
 
      l0 x                # loop
    ] s0
    l0 x
 
    lm 32 + P             # print "pixel"
 
    lw 1 + sw             # w+=1
    l1 x                  # loop
  ] s1
  l1 x
 
  A P                     # linefeed
 
  lh 1 + sh               # h+=1
  l2 x                    # loop
] s2
l2 x