home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / PLOTXY.DI$ / COMET.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  1.5 KB  |  59 lines

  1. function comet(x, y, p)
  2. %COMET    Comet plot.
  3. %    COMET(Y) displays an animated comet plot of the vector Y.
  4. %    COMET(X,Y) displays an animated comet plot of vector Y vs. X.
  5. %    COMET(X,Y,p) uses a comet of length p*length(Y).  Default is p = 0.10.
  6. %    COMET, by itself, is self demonstrating.
  7. %    Example:
  8. %        t = -pi:pi/200:pi;
  9. %        comet(t,tan(sin(t))-sin(tan(t)))
  10. %    See also QUAKEDEMO, COMET3.
  11.  
  12. %    Charles R. Denham, MathWorks, 1989.
  13. %    Revised 2-9-92, LS and DTP; 8-18-92, 11-30-92 CBM.
  14. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  15.  
  16. if nargin == 0,
  17.    x = -pi:pi/200:pi;
  18.    y = tan(sin(x))-sin(tan(x));
  19.    p = 0.1;
  20. else
  21.   if nargin < 2, y = x; x = 1:length(y); end
  22.   if nargin < 3, p = 0.10; end
  23. end
  24.  
  25. clf
  26. axis([min(x) max(x) min(y) max(y)])
  27.  
  28. % Cyan circle head, yellow line body, and magenta line tail.
  29. head = line('color','c','linestyle','o','erase','xor','xdata',x(1),'ydata',y(1));
  30. body = line('color','y','linestyle','-','erase','none','xdata',[],'ydata',[]);
  31. tail = line('color','m','linestyle','-','erase','none','xdata',[],'ydata',[]);
  32.  
  33. m = length(x);
  34. k = round(p*m);
  35.  
  36. % Grow the body
  37. for i = 2:k+1
  38.    j = i-1:i;
  39.    set(head,'xdata',x(i),'ydata',y(i))
  40.    set(body,'xdata',x(j),'ydata',y(j))
  41.    drawnow
  42. end
  43.  
  44. % Primary loop
  45. for i = k+2:m
  46.    j = i-1:i;
  47.    set(head,'xdata',x(i),'ydata',y(i))
  48.    set(body,'xdata',x(j),'ydata',y(j))
  49.    set(tail,'xdata',x(j-k),'ydata',y(j-k))
  50.    drawnow
  51. end
  52.  
  53. % Clean up the tail
  54. for i = m+1:m+k
  55.    j = i-1:i;
  56.    set(tail,'xdata',x(j-k),'ydata',y(j-k))
  57.    drawnow
  58. end
  59.