]> Creatis software - CreaPhase.git/blob - octave_packages/m/plot/comet.m
update packages
[CreaPhase.git] / octave_packages / m / plot / comet.m
1 ## Copyright (C) 2008-2012 Ben Abbott
2 ##
3 ## This file is part of Octave.
4 ##
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
9 ##
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 ## General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING.  If not, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn  {Function File} {} comet (@var{y})
21 ## @deftypefnx {Function File} {} comet (@var{x}, @var{y})
22 ## @deftypefnx {Function File} {} comet (@var{x}, @var{y}, @var{p})
23 ## @deftypefnx {Function File} {} comet (@var{ax}, @dots{})
24 ## Produce a simple comet style animation along the trajectory provided by
25 ## the input coordinate vectors (@var{x}, @var{y}), where @var{x} will default
26 ## to the indices of @var{y}.
27 ##
28 ## The speed of the comet may be controlled by @var{p}, which represents the
29 ## time which passes as the animation passes from one point to the next.  The
30 ## default for @var{p} is 0.1 seconds.
31 ##
32 ## If @var{ax} is specified the animation is produced in that axis rather than
33 ## the @code{gca}.
34 ## @end deftypefn
35
36 ## Author: Ben Abbott bpabbott@mac.com
37 ## Created: 2008-09-21
38
39 function comet (varargin)
40
41   [h, varargin, nargin] = __plt_get_axis_arg__ ("comet", varargin{:});
42
43   if (nargin == 0)
44     print_usage ();
45   elseif (nargin == 1)
46     y = varargin{1};
47     x = 1:numel(y);
48     p = 0.1;
49   elseif (nargin == 2)
50     x = varargin{1};
51     y = varargin{2};
52     p = 0.1;
53   elseif (nargin == 3)
54     x = varargin{1};
55     y = varargin{2};
56     p = varargin{3};
57   endif
58
59   oldh = gca ();
60   unwind_protect
61     axes (h);
62     newplot ();
63     theaxis = [min(x), max(x), min(y), max(y)];
64     num = numel (y);
65     dn = round (num/10);
66     for n = 1:(num+dn);
67       m = n - dn;
68       m = max ([m, 1]);
69       k = min ([n, num]);
70       h = plot (x(1:m), y(1:m), "r", x(m:k), y(m:k), "g", x(k), y(k), "ob");
71       axis (theaxis);
72       drawnow ();
73       pause (p);
74     endfor
75   unwind_protect_cleanup
76     axes (oldh);
77   end_unwind_protect
78
79 endfunction
80
81 %!demo
82 %! clf
83 %! t = 0:.1:2*pi;
84 %! x = cos(2*t).*(cos(t).^2);
85 %! y = sin(2*t).*(sin(t).^2);
86 %! comet(x,y)
87
88