%Benadert de Mandelbrotset van f(z) = z^2 +c.
%initialisatie
N = 1000;
MAXITER=400;
z=0;

%Window
xmin=-1;
xmax = 1;
ymax = 1 ;
ymin = -1;

%coordinaatgrid
c = ones(N+1,1)*(xmin:(xmax-xmin)/N:xmax);
Romeo = transpose(ones(N+1,1)*(ymin:(ymax-ymin)/N:ymax));
c = c + 1i*Romeo;
mandelbrotset = zeros(N+1);

%main loop
for n=1:MAXITER
    z = z.^2 + c;
    mandelbrotset = mandelbrotset + (~mandelbrotset).*(abs(z)>2)*n;
end
%endval = endval+MAXITER * (~endval);

%plotting & saving
h=figure();
colormap(hot)
imagesc(mandelbrotset)
saveas(h,'mandelbrot','fig')
