image thumbnail
from Sierpinski triangle by Guan Wenye
A cellular automation approach to Sierpinski triangle

sierpinski.m
 

%this is a script code,just run it !
% a cellular automation approach to the generation of sierpinski triangle

a=zeros(1001,1801);% The width and length of the canvas
a(1,900)=1;
for k=2:1001
    for l=2:1800
        if a(k-1,l-1)==0 & a(k-1,l)==0 &a(k-1,l+1)==1;
            a(k,l)=1;
        elseif a(k-1,l-1)==1 & a(k-1,l)==0 & a(k-1,l+1)==0;
            a(k,l)=1;
        end
    end
end
spy(a);

Contact us at files@mathworks.com