% MATLAB code for drawing DLA by Chris Bishop
% Calls auxilary file plotcirc.m

function out=dla(n)
clear centers;
clear lograd;
tic;
centers=[0];
counter=1;
attempts=1;
% centers=zeros(1,10^7);
figure;
hold on;
for k=1:n
maxradius=max(abs(centers));
z=(maxradius+1)* exp(2 * pi * i * random('unif',0,1));
step=min(abs(z-centers))-2;
while((step>.1)&&(step<5000))
z=z+ step * exp( 2 * pi * i * random('unif',0,1));
step=min(abs(z-centers))-2;
%%% laststep=abs(z-centers(length(centers)))-2;
end % while
if (step<.2)
attempts=attempts+1;
%%% if abs(step-laststep)<.1
counter=counter+1;
centers(counter)=z;
%%% end % if
end % if
if mod(k,1000)==0
title(['DLA, n = ',num2str(k)])
% title('DLA');
scatter(real(centers),imag(centers) ,'k','.');
drawnow;
%rad(k/1000)=max(abs(centers));
%lograd(k/1000)=log(rad(k/1000))/log(k);
%save('lograd');
%save('centers');
[k/1000,toc]
end % if
end % for k
figure
hold on;
title(['DLA, n = ',num2str(length(centers))])
colormap jet;
%colormap winter;
scatter(real(centers),imag(centers),[],[1:length(centers)],'.');
% figure;
% hold on;
% title('Plot of log(radius)/log(n)');
% plot(lograd);
toc;
return