Biologically Inspired Images/Science
Cellular Automata in Matlab
hrlifestyle
2010. 8. 23. 21:01
- Conway's life.
The rule is:- Sum the 8 nearest neighbors
- If the sum=2 then the state does not change
- If the sum=3 then the state=1
- Otherwise the state=0
x = 2:n-1;
y = 2:n-1;
%nearest neighbor sum
sum(x,y) = cells(x,y-1) + cells(x,y+1) + ...
cells(x-1, y) + cells(x+1,y) + ...
cells(x-1,y-1) + cells(x-1,y+1) + ...
cells(3:n,y-1) + cells(x+1,y+1);
% The CA rule
cells = (sum==3) | (sum==2 & cells);
- Sum the 8 nearest neighbors