
% Mandelbrot fractal
% Ricardo Carretero Mar'2003

Pc = inline('[z.^2+c]','c','z');

Nx=850;
Ny=670;
x=linspace(-2.1,0.5,Nx);
y=linspace(-1.2,1.2,Ny);
[X,Y]=meshgrid(x,y);
c=X+i*Y;
leave=0*c;

Nitmax=256;
z=0;
zmax=Nitmax;

colvec=jet(1*Nitmax);
colvec=colvec([1*Nitmax:-1:1],:,:);
colvec(1,:)=[0 0 0];
figure(1)
clf

for j=1:Nitmax
 z=Pc(c,z);
 out=abs(z)>zmax;
 z=z-out.*z;
 c=c-out.*c;
 leave=leave+out*j;
  if(mod(j,10)==0)
  j
  figure(1)
  surf(X,Y,(leave/256).^(0.5));
  shading interp;
  colormap(colvec);
  view([0 90]);
  axis tight;
%  colorbar
  pause(0.0001)
 end
end

figure(1)
surf(X,Y,(leave/256).^(0.5));
shading interp;
colormap(colvec);
view([0 90]);
axis tight;
% colorbar
pause(0.0001)

