• Remix
  • Share
  • New Entry

  • ME

  • /
  • Conway's Life Begins at 40

on 21 Nov 2023
  • 11
  • 23
  • 0
  • 3
  • 497
drawframe(1);
Write your drawframe function below
function drawframe(f)
% Setup key parameters (including rng seed)
rng(0)
width=50;
mag=5;
% Set initial condition (to spell out 40)
state = zeros(width,width);
state([8 9 42 43],29:43) = 1;
state(8:43,[29 30 42 43]) = 1;
state([32 33],8:23) = 1;
state(8:43,[19 20]) = 1;
state(8:9,18) = 1;
state(31,8) = 1;
for k=1:8
state(8+(k-1)*3:11+(k-1)*3,[17-(k-1) 16-(k-1)]) = 1;
end
state(8,16) = 0;
% Life calculations and plotting
h_fig=imshow(state,'InitialMagnification', 'fit');
shutter=ones(3,3);
if f>4
for i=1:2*(f-4)
counter=conv2(state,shutter);
ctr=counter(2:width+1,2:width+1);
state=(state&(ctr==3|ctr==4))|((~state)&(ctr==3));
end
end
h_fig.CData=state;
set(gcf,'Color','k')
end
Animation
Remix Tree