DLA

initialization(optimized)

Module[{nx,ny,ix,iy,is,rr,g,pp},
runStick=Compile[{{ag,_Integer,2},{mxs,_Integer}},
g=ag;
nx=Dimensions[g][[1]];
ny=Dimensions[g][[2]];
ix=iy=0;
Do[If[g[[x,y]]==-1,ix=x;iy=y;],{x,1,nx},{y,1,ny}];
If[ix>0,
is=0;
While[
is<mxs&&
g[[ Mod[ix-1+1,nx]+1,iy]]==0 &&
g[[ Mod[ix-1-1,nx]+1, iy]]==0 &&
g[[ ix, Mod[iy-1+1,ny]+1]]==0&&
g[[ ix,Mod[iy-1-1,ny]+1]]==0
,
is++;
rr=RandomReal[];
g[[ix,iy]]=0;
If[rr<0.25,ix=Mod[ix-1-1,nx]+1];
If[0.25≤rr<0.5,ix=Mod[ix-1+1,nx]+1];
If[0.5≤rr<0.75,iy=Mod[iy-1-1,ny]+1];
If[0.75≤rr,iy=Mod[iy-1+1,ny]+1];
g[[ix,iy]]=-1;
];
If[is<mxs,g[[ix,iy]]=1];
];
g
,{{g,_Integer,2},{nx,_Integer},{ny,_Integer},{ix,_Integer},{iy,_Integer},{is,_Integer}}
];
]

Module[{nx,ny,ix,iy,ixp,ixm,iyp,iym,is,rr,pp},
runStick=Compile[{{g,_Integer,2},{sxy,_Integer,1},{mxs,_Integer}},
nx=Dimensions[g][[1]];
ny=Dimensions[g][[2]];
ix=sxy[[1]];iy=sxy[[2]];
ixp=Min[nx,ix+1];ixm=Max[1,ix-1];iyp=Min[ny,iy+1];iym=Max[1,iy-1];
is=0;
While[
is<mxs&&
g[[ixp,iy]]==0 &&
g[[ixm, iy]]==0 &&
g[[ ix,iyp]]==0&&
g[[ ix,iym]]==0
,
is++;
rr=RandomReal[];
If[rr<0.25,
ixm=ix; ix=ixp; ixp=Min[nx,ix+1];,
If[rr<0.5,
ixp=ix;ix=ixm;ixm=Max[1,ix-1];,
If[rr<0.75,
iym=iy;iy=iyp; iyp=Min[iy+1,ny];,
iyp=iy;iy=iym;iym=Max[1,iy-1]
]]];
];
If[is<mxs,-{ix,iy},{ix,iy}]
,{{nx,_Integer},{ny,_Integer},{ix,_Integer},{iy,_Integer},{ixp,_Integer},{iyp,_Integer},{ixm,_Integer},{iym,_Integer},{is,_Integer}}
];
]

g=ConstantArray[0,{100,100}];
g[[-1]]+=1;

Timing[Do[runStick[g,{1,2},100];,{i,1,100}]]

dynamic

random initialization of the grid

Manipulate[Dynamic[dfig=MatrixPlot[xg,FrameTicks->None]
],
Style["Initialization",Bold],
{{n0,50,"Grid size"},25,250,5,Appearance->"Labeled"},
{{grw,"Seed","Growth mode"},{"Seed","Surface"}},
Button["reset",
g=ConstantArray[0,{n0,n0}];md=2;np={1,1};
Switch[mgrw=grw,"Seed",g[[Round[n0/2],Round[n0/2]]]=1,"Surface",g[[-1]]+=1];
xg=g;
,ImageSize->80],
Style["Runtime options",Bold],
{{dt,100,"Step Size"},1,1000,Appearance->"Labeled"},
{{mxst,1000,"Deposited particles"},{10,100,1000,10000}},
Button["Go!",
xg=g;
cp=0;
While[cp<mxst,
op=np;
np=runStick[g,np,dt];
If[np[[1]]<0,
cp++;
np*=-1; g[[np[[1]],np[[2]]]]=1;
Switch[mgrw,
"Seed",
md=Max[md,Norm[np-{n0/2,n0/2}]+2];
rt=RandomReal[]*2Pi;
np=Max[Min[#1,n0],1]&/@Round[{n0/2,n0/2}+md*{Cos[rt],Sin[rt]}];,
"Surface",
md=Max[md,n0-np[[1]]+2];
np={Max[1,n0-md],RandomInteger[{1,n0}]};
]
];
xg=g;xg[[np[[1]],np[[2]] ]]=-1;
];

,ImageSize->80,Method->"Queued"],SaveDefinitions->True
]