%Animated radnom walk in two variables
X=[0];
Y=[0];
for i = 2:100000
D  = randi(4);
    if (D == 1)
        X(i) = X(i-1)+1;
        Y(i) = Y(i-1);
    elseif  (D == 2)
        X(i) = X(i-1)-1;
        Y(i) = Y(i-1);
    elseif (D == 3)
        X(i) = X(i-1);
        Y(i) = Y(i-1)+1;
    elseif (D == 4)
        X(i) = X(i-1);
        Y(i) = Y(i-1)-1;
    end
    if ((X(i)==0) && (Y(i)==0))
        disp('Origin!');    
    end
    if (mod(i,100)==0)
       plot(X,Y);
        axis equal;
        pause(1/30);
    end
end
