function volfram(pravilo, pocetni, iter)

% poc=zeros(1,1000); poc(500)=1; volfram(90, poc, 1000);
% poc=round(rand(1,300)); volfram(18, poc, 300);
% volfram(126, poc, 300);
% volfram(183, poc, 200);
% pravilo=[18 30 45 73 89 101 102 105 109 110 126 129 135 ...
%        137 149 151 153 161 167 169 181 182 183 193 195 225];

sirina=length(pocetni);
pr=dec2bin(pravilo,8);
A=zeros(iter, sirina); 
A(1,:)=pocetni;

for i=1:8
    p(i)=str2num(pr(i));
end
for i=2:iter
    for j=2:sirina-1 
        l=A(i-1,j-1); %levi
        s=A(i-1,j);  %sredisnji
        d=A(i-1,j+1); %desni
        if(( l && s && d && p(1)) || ...
           ( l && s && ~d && p(2)) || ...
           ( l && ~s && d && p(3)) || ...
           ( l && ~s && ~d && p(4)) || ...
           (~l &&  s && d && p(5)) || ...
           (~l && s && ~d && p(6)) || ...
           (~l && ~s && d && p(7)) || ...
           (~l && ~s &&~d && p(8)) )
            A(i,j)=1;
        end
    end
end

spy(A)