Mercurial > hg > octave-lyh
annotate scripts/plot/comet.m @ 8240:5cfeb7bc497a
comet.m,hold.m: validate axes handle
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Mon, 20 Oct 2008 10:31:17 -0400 |
parents | 7799d8c38312 |
children | a013ff655ca4 |
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 ## | |
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 (); | |
8240
5cfeb7bc497a
comet.m,hold.m: validate axes handle
Ben Abbott <bpabbott@mac.com>
parents:
8236
diff
changeset
|
43 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
|
44 && strcmpi (get (varargin{1}, "type"), "axes")) |
8126 | 45 axes (varargin{1}); |
46 varargin = varargin(2:end); | |
47 numargin = nargin - 1; | |
48 else | |
49 numargin = nargin; | |
50 endif | |
51 | |
52 p = 0.1; | |
53 if (numargin == 1) | |
54 y = varargin{1}; | |
55 x = 1:numel(y); | |
56 elseif (numargin == 2) | |
57 x = varargin{1}; | |
58 y = varargin{2}; | |
59 elseif (numargin == 3) | |
60 x = varargin{1}; | |
61 y = varargin{2}; | |
62 p = varargin{3}; | |
63 else | |
64 print_usage (); | |
65 endif | |
66 | |
67 theaxis = [min(x), max(x), min(y), max(y)]; | |
68 num = numel (y); | |
69 dn = round (num/10); | |
70 for n = 1:(num+dn); | |
71 m = n - dn; | |
72 m = max ([m, 1]); | |
73 k = min ([n, num]); | |
74 h = plot (x(1:m), y(1:m), "r", x(m:k), y(m:k), "g", x(k), y(k), "ob"); | |
75 axis (theaxis); | |
76 drawnow (); | |
77 pause (p); | |
78 endfor | |
79 | |
80 endfunction | |
81 | |
82 %!demo | |
8236 | 83 %! close all; |
8126 | 84 %! t = 0:.1:2*pi; |
85 %! x = cos(2*t).*(cos(t).^2); | |
86 %! y = sin(2*t).*(sin(t).^2); | |
87 %! comet(x,y) | |
88 | |
89 |