annotate scripts/plot/comet.m @ 11341:3c7ba1e3dc21

Add missing option slice for pie and pie3
author Kai Habel <kai.habel@gmx.de>
date Fri, 10 Dec 2010 19:53:06 +0100
parents 2c356a35d7f5
children a0278a856516
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8817
diff changeset
1 ## Copyright (C) 2008, 2009 Ben Abbott
8126
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
2 ##
11104
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 10793
diff changeset
3 ## This file is part of Octave.
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 10793
diff changeset
4 ##
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 10793
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 10793
diff changeset
6 ## under the terms of the GNU General Public License as published by
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 10793
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 10793
diff changeset
8 ## your option) any later version.
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 10793
diff changeset
9 ##
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 10793
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 10793
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 10793
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 10793
diff changeset
13 ## General Public License for more details.
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 10793
diff changeset
14 ##
8126
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
15 ## 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
16 ## along with Octave; see the file COPYING. If not, see
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
18
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
19 ## -*- texinfo -*-
10793
be55736a0783 Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
20 ## @deftypefn {Function File} {} comet (@var{y})
8126
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
21 ## @deftypefnx {Function File} {} comet (@var{x}, @var{y})
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
22 ## @deftypefnx {Function File} {} comet (@var{x}, @var{y}, @var{p})
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
23 ## @deftypefnx {Function File} {} comet (@var{ax}, @dots{})
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
24 ## Produce a simple comet style animation along the trajectory provided by
9040
dbd0c77e575e Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
25 ## the input coordinate vectors (@var{x}, @var{y}), where @var{x} will default
8126
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
26 ## to the indices of @var{y}.
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
27 ##
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
28 ## The speed of the comet may be controlled by @var{p}, which represents the
9040
dbd0c77e575e Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
29 ## time which passes as the animation passes from one point to the next. The
8126
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
30 ## default for @var{p} is 0.1 seconds.
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
31 ##
9040
dbd0c77e575e Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
32 ## If @var{ax} is specified the animation is produced in that axis rather than
8126
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
33 ## the @code{gca}.
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
34 ## @end deftypefn
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
35
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
36 ## Author: Ben Abbott bpabbott@mac.com
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
37 ## Created: 2008-09-21
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 function comet (varargin)
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
40
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
41 if (nargin == 0)
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
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})
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
44 && strcmpi (get (varargin{1}, "type"), "axes"))
8126
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
45 axes (varargin{1});
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
46 varargin = varargin(2:end);
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
47 numargin = nargin - 1;
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
48 else
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
49 numargin = nargin;
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
50 endif
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
51
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
52 p = 0.1;
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
53 if (numargin == 1)
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
54 y = varargin{1};
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
55 x = 1:numel(y);
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
56 elseif (numargin == 2)
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
57 x = varargin{1};
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
58 y = varargin{2};
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
59 elseif (numargin == 3)
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
60 x = varargin{1};
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
61 y = varargin{2};
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
62 p = varargin{3};
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
63 else
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
64 print_usage ();
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
65 endif
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
66
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
67 theaxis = [min(x), max(x), min(y), max(y)];
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
68 num = numel (y);
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
69 dn = round (num/10);
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
70 for n = 1:(num+dn);
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
71 m = n - dn;
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
72 m = max ([m, 1]);
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
73 k = min ([n, num]);
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
74 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
75 axis (theaxis);
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
76 drawnow ();
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
77 pause (p);
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
78 endfor
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 endfunction
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
81
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
82 %!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
83 %! clf
8126
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
84 %! t = 0:.1:2*pi;
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
85 %! x = cos(2*t).*(cos(t).^2);
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
86 %! y = sin(2*t).*(sin(t).^2);
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
87 %! comet(x,y)
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
88
a012580f0d2f comet.m: New File.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
89