Mercurial > hg > octave-nkf
annotate scripts/plot/comet.m @ 8817:03b7f618ab3d
include docstrings for new functions in the manual
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 19 Feb 2009 15:39:19 -0500 |
parents | a013ff655ca4 |
children | eb63fbe60fab |
rev | line source |
---|---|
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 ## @end deftypefn | |
33 | |
34 ## Author: Ben Abbott bpabbott@mac.com | |
35 ## Created: 2008-09-21 | |
36 | |
37 function comet (varargin) | |
38 | |
39 if (nargin == 0) | |
40 print_usage (); | |
8240
5cfeb7bc497a
comet.m,hold.m: validate axes handle
Ben Abbott <bpabbott@mac.com>
parents:
8236
diff
changeset
|
41 elseif (numel (varargin{1}) == 1 && ishandle (varargin{1}) |
5cfeb7bc497a
comet.m,hold.m: validate axes handle
Ben Abbott <bpabbott@mac.com>
parents:
8236
diff
changeset
|
42 && strcmpi (get (varargin{1}, "type"), "axes")) |
8126 | 43 axes (varargin{1}); |
44 varargin = varargin(2:end); | |
45 numargin = nargin - 1; | |
46 else | |
47 numargin = nargin; | |
48 endif | |
49 | |
50 p = 0.1; | |
51 if (numargin == 1) | |
52 y = varargin{1}; | |
53 x = 1:numel(y); | |
54 elseif (numargin == 2) | |
55 x = varargin{1}; | |
56 y = varargin{2}; | |
57 elseif (numargin == 3) | |
58 x = varargin{1}; | |
59 y = varargin{2}; | |
60 p = varargin{3}; | |
61 else | |
62 print_usage (); | |
63 endif | |
64 | |
65 theaxis = [min(x), max(x), min(y), max(y)]; | |
66 num = numel (y); | |
67 dn = round (num/10); | |
68 for n = 1:(num+dn); | |
69 m = n - dn; | |
70 m = max ([m, 1]); | |
71 k = min ([n, num]); | |
72 h = plot (x(1:m), y(1:m), "r", x(m:k), y(m:k), "g", x(k), y(k), "ob"); | |
73 axis (theaxis); | |
74 drawnow (); | |
75 pause (p); | |
76 endfor | |
77 | |
78 endfunction | |
79 | |
80 %!demo | |
8790
a013ff655ca4
Trivial changes to demos to produce a more pleasant output for octave+gnuplot+aquaterm.
Ben Abbott <bpabbott@mac.com>
parents:
8240
diff
changeset
|
81 %! clf |
8126 | 82 %! t = 0:.1:2*pi; |
83 %! x = cos(2*t).*(cos(t).^2); | |
84 %! y = sin(2*t).*(sin(t).^2); | |
85 %! comet(x,y) | |
86 | |
87 |