function output = SteppingStone_continue(input , duration ,pause_yes_or_no)
%SteppingStone_continues running the stepping stone process duration times.

[n,~]=size(input);
num_colors=max(unique(input));
initial_step=input;
figure(1); 
colormap(hsv(num_colors));

for i=1:duration
    random_ind=randi(n^2);
    adjacent_inds=zeros(1,8);
    
    adjacent_inds(1)=mod(random_ind-1,n.^2);
    adjacent_inds(2)=mod(random_ind-1+n,n.^2);
    adjacent_inds(3)=mod(random_ind+n,n.^2);
    adjacent_inds(4)=mod(random_ind+n+1,n.^2);
    adjacent_inds(5)=mod(random_ind+1,n.^2);
    adjacent_inds(6)=mod(random_ind-n+1,n.^2);
    adjacent_inds(7)=mod(random_ind-n,n.^2);    
    adjacent_inds(8)=mod(random_ind-n-1,n.^2);
    adjacent_inds(adjacent_inds==0)=n.^2;
    pick_one=randi(8);
    random_neighbor_color=initial_step(adjacent_inds(pick_one));
    initial_step(random_ind)=random_neighbor_color;
    figure(1);
    image(initial_step);  
    title('current state')
    if pause_yes_or_no==1
        change_spot=zeros(n);
        change_spot(random_ind)=1;
        figure(2);
        imagesc(change_spot);
        title('tile changed')
        pause
    end
end

output=initial_step;


end

