%Plots the Mandelbrot fractal
clear;
norm2 = @(z) z.*conj(z); %|z|^2
f=@(z,c) z.^2 + c; 
r = [-3:0.005:2];
%P = "pixels"
P = repmat(r,length(r),1) + repmat((i*r)',1,length(r)); 
P = reshape(P,1,[]);
%D = function values
D = zeros(1,length(P));
NUM = 25; 
clf;
for j=1:NUM
    D=f(D,P);
    N = norm2(D); %N = norms of values   
    D = D(N < 17); %throw away all values with large norms
    P = P(N < 17); %throw away corresponding pixels   
    w = (NUM-j)/(NUM); %setting color
    color = [w w w];    
    %color = hsv2rgb([w, 0.9, 0.9]);
    plot(P,'s','MarkerSize',1, 'MarkerFaceColor',color, 'MarkerEdgeColor', color);
    axis equal;
    hold on;
    pause(1/5);
end;
