- /
-
Rule 30
on 29 Nov 2023
- 10
- 21
- 1
- 0
- 624
drawframe(1);
Write your drawframe function below
function drawframe(f)
rule30 = containers.Map({'111', '110', '101', '100', '011', '010', '001', '000'},...
{'0', '0', '0', '1', '1', '1', '1', '0'});
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,rule30);
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,rule30)
input = pad(input,length(input)+2,'both','0'); % padding
output = '';
for i = 1:length(input)-2
output(i) = rule30(input(i:i+2));
end
output = char(output);
end
end