• Remix
  • Share
  • New Entry

on 30 Nov 2023
  • 13
  • 26
  • 0
  • 2
  • 624
drawframe(1);
Write your drawframe function below
function drawframe(f)
%% cellular automate
%% rule 73
rule73 = containers.Map({'111', '110', '101', '100', '011', '010', '001', '000'},...
{'0', '1', '0', '0', '1', '0', '0', '1'});
n = 241; % must be odd for symmetry
scale = linspace(1,255,n);
a = '1';
a = pad(a,n,'both','0');
img = zeros(length(a));
img(1, :) = arrayfun(@(x) str2double(a(x)), 1:length(a)).*scale;
for j = 2:f*5
a = applyRule(a,rule73);
img(j,:) = arrayfun(@(x) str2double(a(x)), 1:length(a)).*scale;
end
cmap = turbo;
indexed_img = ind2rgb(uint16(img),cmap);
imshow(indexed_img);
function output = applyRule(input,rule73)
input = pad(input,length(input)+2,'both','0'); % padding
output = '';
for i = 1:length(input)-2
output(i) = rule73(input(i:i+2));
end
output = char(output);
end
end
Animation
Remix Tree