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 .




to mandelbrot :left :bottom :side :size
  cs setpensize [1 1]
  make "inc :side/:size
  make "zr :left
  repeat :size [
    make "zr :zr + :inc
    make "zi :bottom
    pu
    setxy repcount - :size/2  minus :size/2
    pd
    repeat :size [
      make "zi :zi + :inc
      setpencolor count.color calc :zr :zi
      fd 1 ] ]
end
 
to count.color :count
  ;op (list :count :count :count)
  if :count > 256 [op 0]	; black
  if :count > 128 [op 7]	; white
  if :count >  64 [op 5]	; magenta
  if :count >  32 [op 6]	; yellow
  if :count >  16 [op 4]	; red
  if :count >   8 [op 2]	; green
  if :count >   4 [op 1]	; blue
  op 3				; cyan
end
 
to calc :zr :zi [:count 0] [:az 0] [:bz 0]
  if :az*:az + :bz*:bz > 4 [op :count]
  if :count > 256 [op :count]
  op (calc :zr :zi (:count + 1) (:zr + :az*:az - :bz*:bz) (:zi + 2*:az*:bz))
end
 
mandelbrot -2 -1.25 2.5 400