function cellular_motomata

%set these four parameters
worm_length=50;
num_cycles=100;
age_unit=.1;
marquee_method=1;

%choose an initial state by de/commenting (and/or changing the repeated vector)
%worm=round(rand(1,worm_length))
%worm=repmat([1 1 0],1,worm_length);
worm=repmat([5 4 3 2 1 0],1,worm_length);  %unclear what this means w/ automata_method


automata_method=bitcmp(marquee_method,1);
close all
figure
colormap('gray')
set(gcf,'position',[67 877 1210 78])

for i=1:num_cycles
    if marquee_method
        worm=cat(2,worm(2:end),worm(1));
    elseif automata_method
        for j=1:length(worm)
            %making the indices wrap around so the ends are contiguous
            if j==1,to_the_left=length(worm);else to_the_left=j-1;end
            if j==length(worm),to_the_right=1;else to_the_right=j+1;end
            
            %rules of change
            if worm(j)
                if worm(to_the_right)&~worm(to_the_left)
                elseif ~worm(to_the_right)&worm(to_the_left)
                    worm(j)=worm(j)-(3*age_unit);
                elseif worm(to_the_right)&worm(to_the_left)
                elseif ~worm(to_the_right)&~worm(to_the_left)
                    worm(j)=0;
                end
            else
                if ~worm(to_the_right)
                    worm(j)=1;
                end
            end
            worm(find(worm<0))=0;    
        end
    end
    imagesc(ceil(worm))
    pause(.1)
end