function life
size = 105;
A = zeros (size, size);
A = center (A, pattern);
c = [ 1 1 1; 0 0 0 ];
colormap (c);                % you can set this ahead of time
for i=1:1000
   A = update (A);
   pcolor (A);
   shading flat;             % but this only after the fact
   pause (0.01);             % we need this to update the figure
end


function C = update (A)
% compute the next iteration of life using matrix operations
C = A;


function B = updateIter (A)
% compute the next iteration of life using for loops
B = A;


function result = center (A, B)
% copy the matrix B into the middle of matrix a
r = round ((size(A,1) - size(B,1)) / 2);
c = round ((size(A,2) - size(B,2)) / 2);
result = copymatrix (A, B, r, c);


function result = copymatrix (A, B, r, c)
% copy the matrix B into matrix A at the location r, c
height = size (B,1);
width  = size (B,2);
A(r:r+height-1,c:c+width-1) = B;
result = A;

function A = pattern ()
A = zeros(100);
A(41:75,41:75) = eye(35);
A(75:76,76:79) = 1; A(77,[76 77 79]) = 1;
A(33,71:73) = 1; A(34:35,[71 73]) = 1;
A(2,6) = 1; A(2,7) = 1; A(3,6) = 1; A(3,7) = 1;
A(13,6) = 1; A(13,7) = 1; A(13,8) = 1;
A(14,5) = 1; A(14,9) = 1;
A(15,4) = 1; A(15,10) = 1;
A(16,:) = A(14,:);
A(17,:) = A(13,:);
A(18,:) = A(13,:);
A(23,4) = 1; A(23,5) = 1; A(23,6) = 1;
A(24,3) = 1; A(24,4) = 1; A(24,6) = 1; A(24,7) = 1;
A(25,:) = A(24,:); 
A(26,:) = A(24,:); A(26,5) = 1;
A(27,2) = 1; A(27,3) = 1; A(27,7) = 1; A(27,8) = 1;
A(32,6) = 1; A(32,7) = 1;
A(36,4) = 1; A(36,5) = 1;
A(37,:) = A(36,:);
A(83,66) = 1;
A(84,:) = A(83,:);
A(85,65) = 1; A(85,67) = 1;
A(86:87,:) = A(83:84,:);
A(88:89,:) = A(83:84,:);
A(90,:) = A(85,:);
A(91:92,:) = A(83:84,:);
A(80,11:15) = 1; A(80,17:21) = 1;
A(4:5,49:50) = 1;
A(8,48:50) = 1; A(9,:) = A(8,:);
A(13,46:47) = 1; A(13,51:52) = 1;
A(14,47:51) = 1;
A(15,48:50) = 1;
A(16,49) = 1;
A(24:25,49:50) = 1;