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 .




#! /usr/bin/octave -qf
global width = 200;
global height = 200;
maxiter = 100;
 
z0 = 0;
global cmax = 1 + i;
global cmin = -2 - i;
 
function cs = pscale(c)
  global cmax;
  global cmin;
  global width;
  global height;
  persistent px = (real(cmax-cmin))/width;
  persistent py = (imag(cmax-cmin))/height;
  cs = real(cmin) + px*real(c) + i*(imag(cmin) + py*imag(c));
endfunction
 
ms = zeros(width, height);
for x = 0:width-1
  for y = 0:height-1
    z0 = 0;
    c = pscale(x+y*i);
    for ic = 1:maxiter
      z1 = z0^2 + c;
      if ( abs(z1) > 2 ) break; endif
      z0 = z1;
    endfor
    ms(x+1, y+1) = ic/maxiter;
  endfor
endfor
 
saveimage("mandel.ppm", round(ms .* 255).', "ppm");