


% this cheats by only checking last 5000 sites  and 5000

%randomly chosen sites to compute distance



% start with line



function   out=DLA2(n)
   tic;
   centers=zeros(1,n);
   num=1000;
   for k=1:num
       centers(k)= (num/pi)*exp(2*pi*i*k/num);
   end %for k
   counter=num;
   randnums=random('unif',0,1,[1,100*n]);
   randcounter=1;
   
   % DRAW STARTING CONFGIURATION
   figure;    hold on;  
   %title(['DLA from circle, n = ',num2str(counter)])
       %  title('DLA');
   scatter(real(centers),imag(centers) ,'k','.'); drawnow;

   
  % use this is redrawing intermediate configurations in same window
  % if n>9999
  %     figure;  hold on;
  % end % if n

   while counter < n+1
      maxradius=max(abs(centers));
      z=(maxradius+1)* exp(2 * pi * 1i * randnums(randcounter));
      randcounter=randcounter+1;
      step=min(abs(z-centers(1:counter)))-2;
      while((step>.1)&&(step<50000))
         z=z+ step * exp( 2 * pi * 1i * randnums(randcounter));
         randcounter=randcounter+1;
         step=min(abs(z-centers(1:counter)))-2;
      end % while
      if (step<.2)
         counter=counter+1;
         centers(counter)=z;
      end % if
      if mod(counter,10000)==0
        % use this if intermediate drawing go in different widiows
        figure;    hold on;  
        title(['DLA from circle, n = ',num2str(counter)])
       %  title('DLA');
        scatter(real(centers),imag(centers) ,'k','.');
        drawnow;
        [counter/10000,toc]
      end % if
   end % while counter < n+1

   figure;    hold on;   colormap jet;
   %title(['DLA, n = ',num2str(length(centers))])
   scatter(real(centers),imag(centers),[],[1:length(centers)],'.');


   %figure;    hold on;   colormap jet;
   %thin=centers(1:4:length(centers));
   %scatter(real(thin),imag(thin),[],[1:length(thin)],'.');
   %figure;    hold on;   colormap jet;
   %thin=centers(1:10:length(centers));
   %scatter(real(thin),imag(thin),[],[1:length(thin)],'.');



   toc;

return
