%-------------------------------------------------------------------------
%               Create AVI after loop runs: movie2avi
%-------------------------------------------------------------------------

clear;
close all;
clc

x = zeros(1,1000);
y = zeros(1,1000);

x(1) = 500;
y(1) = 500;

tic
for i=1:length(x)
    r = rand;
    if r < .25
        x(i+1) = x(i)+10;
        y(i+1) = y(i)+10;
    elseif r < .5
        x(i+1) = x(i)-10;
        y(i+1) = y(i)+10;
    elseif r < .75
        x(i+1) = x(i)+10;
        y(i+1) = y(i)-10;
    else
        x(i+1) = x(i)-10;
        y(i+1) = y(i)-10;
    end
    
    axis([0 1000 0 1000])
    title(sprintf('x(%d) = %d, y(%d) = %d',i,x(i),i,y(i)))
    plot(x(i+1),y(i+1),'r.')
    hold on
    M(i) = getframe;
end

disp('now to the movie')

movie(M,1)
movie2avi(M, 'walking.avi', 'compression', 'none');