% Simulation of "stair steps" along return map for RW
% Katie Byl, 1/8/2009

% first, run the m-file "RW_return", to define variables!
%RW_return  % <-- to make a clean figure with the RETURN MAP drawn...

% define points for INTERPOLATION function:
omega = [omega_uphill-eps, omega_middle, omega_dnhill+eps];
omega_2 = [omega_uphill_2, omega_middle_2, omega_dnhill_2];

ndo = 1; %200;  % for "random" points.  Set to 1 to click-to-select points.
for k=1:ndo
    if ndo>1
        om_test = 10*(rand-.5); % random initial velocity...
    else
        gg = ginput(1);
        om_test = gg(1);
    end
    om_last = om_test;
    
    i=0;
    for n=1:6  % can make large, but runs more slowly...
        om_new = interp1(omega,omega_2,om_last(end));
        i=i+1;
        pp(i)=plot([om_last(end) om_last(end)],[om_last(end) om_new],'k-');
        drawnow  % force a screen upate
        % pause(.05)  % if you want to watch it "bounce" more slowly...
        i=i+1;
        pp(i)=plot([om_last(end) om_new(end)],[om_new om_new],'k-');
        drawnow
        % pause(.05)
        om_last = [om_last, om_new]; % add to list...
    end
    if abs(om_last(end)-fixed_rolling)<abs(om_last(end)-fixed_stopped)
        mycolor = [0 .8 0];  % rolling fixed point
    else
        mycolor = [1 0 0];  % standing (stopped) fixed point
    end
    for n=1:i
        set(pp(n),'Color',mycolor)
    end
    drawnow  % requiring all these "drawnow" commands may be obsolete?
end
