• Remix
  • Share
  • New Entry

on 6 Nov 2023
  • 8
  • 38
  • 1
  • 1
  • 164
drawframe(1);
Write your drawframe function below
function drawframe(f)
% Based on code by Christopher Creutzig https://blogs.mathworks.com/steve/2022/02/28/a-short-game-of-life/
rng(2)
persistent im;
if f==1
im = rand(20,20)>0.6;
end
t = conv2(im,[2,2,2;2,1,2;2,2,2],"same");
im = (t > 4) & (t < 8);
% Plot the matrix
imagesc(im);
% Set the colormap to black and white
% where 0 maps to white and 1 maps to black
colormap([1 1 1; 0 0 0]);
% Remove axis ticks
axis off;
% Maintain aspect ratio
axis image;
end
Animation
Remix Tree