生存報告書

趣味のメモ

ライフゲーム【matlab】

lifegame.m

gridSize = 500;
numGenerations = 1000;
initialGrid = (rand(gridSize,gridSize) > .75);

% Draw the initial grid
hold off
imagesc(initialGrid);
colormap([1 1 1;0 0.5 0]);
title('Initial Grid');


grid = initialGrid;
% Loop through each generation updating the grid and displaying it
for generation = 1:numGenerations
grid = updateGrid(grid, gridSize);

imagesc(grid);
title(num2str(generation));

drawnow;

end

 updateGrid.m

function X = updateGrid(X, N)
p = [1 1:N-1];
q = [2:N N];
% Count how many of the eight neighbors are alive.
neighbors = X(:,p) + X(:,q) + X(p,:) + X(q,:) + X(p,p) + X(q,q) + X(p,q) + X(q,p);
% A live cell with two live neighbors, or any cell with
% three live neighbors, is alive at the next step.
X = (X & (neighbors == 2)) | (neighbors == 3);
end

 

ひろったやつなので何も頑張ってない

GW中にセルオートマトンで生態系シミュレーション作りたい←だめでした

いずれは地震伝播のシミュ作りたい