Conway's Game of Life: Difference between revisions
Content added Content deleted
Line 2,701: | Line 2,701: | ||
<lang matlab>open(fullfile(matlabroot, 'toolbox', 'matlab', 'demos', 'life.m'))</lang> |
<lang matlab>open(fullfile(matlabroot, 'toolbox', 'matlab', 'demos', 'life.m'))</lang> |
||
Here is an example code, more simple (runs the game of life for N generations in a square of side S) : |
|||
<lang matlab>function GoL(S, N) % |
|||
colormap copper; whitebg('black'); |
|||
G= round(rand(S)); |
|||
A = [S 1:S-1]; B = [2:S 1]; |
|||
for k=1:N |
|||
Sum = G(A,:)+G(B,:)+G(:,B)+G(:,A)+G(A,B)+G(A,A)+G(B,B)+G(B,A); |
|||
G = double((G & (Sum == 2)) | (Sum == 3)); |
|||
surf(G); view([0 90]); pause(0.001) |
|||
end |
|||
end</lang> |
|||
=={{header|Mathematica}}== |
=={{header|Mathematica}}== |