function steppingStones(gridSize,time)
% steppingStones builds a random gridSize x gridSize grid with white and
% black stones, and then runs the stepping stone model on it for length
% time. at each step, select a random stone, and a random neighbor of that
% stone; turn the stone into the color of the selected neighbor. 


%%%%%%% build a random white/black matrix of stones %%%%%%%
mat = zeros(gridSize); %# Your sample matrix


for i = 1:gridSize^2
    mat(i) = randi([0,1]);
    
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%





%%%%%%%%%%% do the following process "time" times %%%%%%%%%%%
for i=1:time
    %%%% select a random stone and a random neighbor, and %%%
    %%%% turn the stone into the color of its neighbor    %%%
    %%%% keep track of the stones' colors, so we know how %%%
    %%%% many white stones are left                       %%%
    
    k = randi(gridSize,1,2); %pick random entry
    

    
    x = randi([-1,1],1,2); %select random direction
        while (x(1) == x(2) && x(1) == 0)
            x = randi([-1,1],1,2);
        end
            

    mat(k(1),k(2)) = mat(mod(k(1) + x(1),gridSize) + 1, mod(k(2)+x(2),gridSize) + 1);
 
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    
    %%%% this part is for plotting and animating the plot %%%%
    colormap(gray);                                            %# Use a gray colormap
    imagesc((1:gridSize)+0.5,(1:gridSize)+0.5,mat);            %# Plot the image
    
    axis equal                                                 %# Make axes grid sizes equal

    set(gca,'XTick',1:(gridSize+1),'YTick',1:(gridSize+1),...  %# Align tick marks
        'XTickLabel',{},'YTickLabel',{},...                    %# Get rid of labels
        'XLim',[1 gridSize+1],'YLim',[1 gridSize+1],...        %# Grid size
        'GridLineStyle','-','XGrid','on','YGrid','on');        %# Put in grid lines
    
    M(i) = getframe;
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
end

                        


end