% this ocde simulates the Eden Model

% on the matrix 0 is open
% 1 is interface
% 2 is where a particle has landed

function Eden(Size,T)

%% make the matrix

M=zeros(Size);

M(1,:)=2; % give it a solid base
M(2,:)=1;

figure(100)
hold on
axis equal
for t=1:T 
    M=growth_equ(M,Size);
%     imagesc(M)
%     drawnow
end
imagesc(M)

end


%% this is teh growth equation
function M=growth_equ(M,Size)

% pick a random column
j=floor(Size(2)*rand(1))+1;


I=find(M(:,j)==1);
i=max(I); % make the particle stick to the first part of the interface it hits

M(i,j)=2; % change the place it hit from an interface to a solid

for x=-1:1;
    for y=-1:1;
        if ((i+y)*(j+x)~=0 && (i+y)<=Size(1) && (j+x)<=Size(1))
            if M(i+y,j+x)==0
             M(i+y,j+x)=1;
            end
        end
    end
end

% % turn off anything that is covered
% I=find(M(:,j)==1);
% i=max(I); % make the particle stick to the first part of the interface it hits
% M(I(I~=i),j)=0;

end
