size=201; ar=zeros(size,size); ar((size+1)/2,(size+1)/2)=100; figure('Position',[100,100,200,200]) ct=0; for i=1:10000 [i,ct] cth=1-2*rand; sth=sqrt(1-cth*cth); sth=sth*(1-2*(rand < .5)); x=round((1+0.5*cth)*(size+1)/2); y=round((1+0.5*sth)*(size+1)/2); for j=1:10000 xlast=x; ylast=y; ch=rand; x=x+1*(ch < .25); x=x-1*((ch >= .25) & (ch < .5)); y=y+1*((ch >= .5) & (ch < .75)); y=y-1*(ch >= .75); if (x < 1 | y < 1 | x > size | y > size) break end if (ar(x,y) == 100) ar(xlast,ylast)=100; ct=ct+1; image(ar) shading flat colormap(waves) axis('square') drawnow break end end end