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