11523
|
1 ## Copyright (C) 2010-2011 Ben Abbott and John W. Eaton |
11382
|
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} {} comet3 (@var{z}) |
|
21 ## @deftypefnx {Function File} {} comet3 (@var{x}, @var{y}, @var{z}, @var{p}) |
|
22 ## @deftypefnx {Function File} {} comet3 (@var{ax}, @dots{}) |
|
23 ## Produce a simple comet style animation along the trajectory provided by |
|
24 ## the input coordinate vectors (@var{x}, @var{y}), where @var{x} will default |
|
25 ## to the indices of @var{y}. |
|
26 ## |
|
27 ## The speed of the comet may be controlled by @var{p}, which represents the |
|
28 ## time which passes as the animation passes from one point to the next. The |
|
29 ## default for @var{p} is 0.1 seconds. |
|
30 ## |
|
31 ## If @var{ax} is specified the animation is produced in that axis rather than |
|
32 ## the @code{gca}. |
|
33 ## @end deftypefn |
|
34 |
|
35 ## Author: jwe |
|
36 ## Created: 2010-12-17 |
|
37 |
|
38 function comet3 (varargin) |
|
39 |
|
40 [h, varargin, nargin] = __plt_get_axis_arg__ ("comet3", varargin{:}); |
|
41 |
|
42 if (nargin == 0 || nargin == 2 || nargin > 4) |
|
43 print_usage (); |
|
44 elseif (nargin == 1) |
|
45 z = varargin{1}; |
|
46 x = y = 1:numel(z); |
|
47 p = 0.1; |
|
48 elseif (nargin == 3) |
|
49 x = varargin{1}; |
|
50 y = varargin{2}; |
|
51 z = varargin{3}; |
|
52 p = 0.1; |
|
53 elseif (nargin == 4) |
|
54 x = varargin{1}; |
|
55 y = varargin{2}; |
|
56 z = varargin{3}; |
|
57 p = varargin{4}; |
|
58 endif |
|
59 |
|
60 oldh = gca (); |
|
61 unwind_protect |
|
62 axes (h); |
|
63 newplot (); |
|
64 theaxis = [min(x), max(x), min(y), max(y), min(z), max(z)]; |
|
65 num = numel (y); |
|
66 dn = round (num/10); |
|
67 for n = 1:(num+dn); |
|
68 m = n - dn; |
|
69 m = max ([m, 1]); |
|
70 k = min ([n, num]); |
|
71 h = plot3 (x(1:m), y(1:m), z(1:m), "r", x(m:k), y(m:k), z(m:k), "g", |
|
72 x(k), y(k), z(k), "ob"); |
|
73 axis (theaxis); |
|
74 drawnow (); |
|
75 pause (p); |
|
76 endfor |
|
77 unwind_protect_cleanup |
|
78 axes (oldh); |
|
79 end_unwind_protect |
|
80 |
|
81 endfunction |
|
82 |
|
83 %!demo |
|
84 %! clf |
|
85 %! t = 0:pi/20:5*pi; |
|
86 %! comet3 (cos(t), sin(t), t, 0.01); |