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