start_number = 10000;

field_size =500;

loops=100;

field=zeros(field_size,field_size);

startpop=random('unid',field_size,2,start_number);

for i=1:start_number

field(startpop(1,i),startpop(2,i))=1;

end

p2=imshow(field);

for l=1: loops

tempfield=field;

for j=2:field_size-1

for k =2:field_size-1

if sum(sum(field(j-1:j+1,k-1:k+1))) <2

tempfield(j,k)=0;

end

if sum(sum(field(j-1:j+1,k-1:k+1))) >4

tempfield(j,k)=0;

end

if sum(sum(field(j-1:j+1,k-1:k+1))) ==3 && field(j,k) == 0

tempfield(j,k)=1;

end

end

end

field=tempfield;

set(p2, 'CData', field);

drawnow;

end