All pastes #31935 Raw Edit

Miscellany

public text v1 · immutable
#31935 ·published 2005-12-01 11:16 UTC
rendered paste body
%sailor drunk man
 %Darvell Powell
 
 %Clear data and command window, standard procedure...
 clc
 clear
 
%Constant Probability
p=0.50
 
%Number of steps nessesary
n=24
 
%Range for planks (y values)
ya=[0:n:n] %Length of 12 (steps)

%inital position of sailor is
%(5,-3)
x = 5;
y = -2;
steps = 0;
dead = 0;
 
%setup parameters for our movie..
reruns=1;                  % number of times movie is to play
fps=2;                     % frames per second

nframes = 25;              % number of frames in the movie
Frames = moviein(nframes); % initialize the matrix 'Frames'
 




%move the poor old man to his destination..
while steps < n && dead == 0
    
      steps = steps + 1;
      r = rand;
      r = r + p;
      
      if r >= 0.75                        % 60% chance of going straight
         y = y + 2;
      elseif r < 0.45    % 20% chance of going right
         y = y + 2;  
         x = x + 2;
      else
         y = y + 2; 
         x = x - 2;  
      end
      
      %First plank
      xa=[-1,-1]
      %Second Plank
      xb=[1,1]
      %Third Plank
      xc=[3,3]
      %Fourth Plank
      xd=[5,5]
      %Fifth Plank
      xe=[7,7]
      %Sixth Plank
      xf=[9,9]
      %Seventh Plank
      xg=[11,11]
 
      %Plot the planks
      plot(xa,ya,xb,ya,xc,ya,xd,ya,xe,ya,xf,ya,xg,ya);
      axis([xa(1)-2, xg(1)+2, ya(1)-3, n+2]);
      hold on

      plot(x,y,'*');
      Frames(:,steps)=getframe;
      hold off
      
 

      
end
%Playback our creation
movie(Frames,reruns,fps)