Mercurial > octave
changeset 26666:5c46c13b43ad
comet3.m: Use constant speed regardless of size of data input.
* comet3.m: Change default time to display each data point to "5 / numel (z)"
so that it scales with input. Update documentation to reflect this.
Use more accurate timing mechanism borrowed from movie.m.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 02 Feb 2019 18:07:47 -0800 |
parents | f9dbc287f908 |
children | 3c4ba50b2024 |
files | scripts/plot/draw/comet3.m |
diffstat | 1 files changed, 11 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/plot/draw/comet3.m Sat Feb 02 11:33:30 2019 -0800 +++ b/scripts/plot/draw/comet3.m Sat Feb 02 18:07:47 2019 -0800 @@ -29,7 +29,7 @@ ## ## The speed of the comet may be controlled by @var{p}, which represents the ## time each point is displayed before moving to the next one. The default for -## @var{p} is 0.1 seconds. +## @var{p} is @code{5 / numel (@var{z})}. ## ## If the first argument @var{hax} is an axes handle, then plot into this axes, ## rather than the current axes returned by @code{gca}. @@ -48,12 +48,12 @@ elseif (nargin == 1) z = varargin{1}; x = y = 1:numel (z); - p = 0.1; + p = 5 / numel (z); elseif (nargin == 3) x = varargin{1}; y = varargin{2}; z = varargin{3}; - p = 0.1; + p = 5 / numel (z); elseif (nargin == 4) x = varargin{1}; y = varargin{2}; @@ -76,6 +76,10 @@ x(1), y(1), z(1), "color", "b", "marker", "o"); axis (limits); # set manual limits to speed up plotting + ## Initialize the timer + t = p; + timerid = tic (); + for n = 2:(num+dn) m = n - dn; m = max ([m, 1]); @@ -83,8 +87,9 @@ set (hl(1), "xdata", x(1:m), "ydata", y(1:m), "zdata", z(1:m)); set (hl(2), "xdata", x(m:k), "ydata", y(m:k), "zdata", z(m:k)); set (hl(3), "xdata", x(k) , "ydata", y(k) , "zdata", z(k)); - drawnow (); - pause (p); + + pause (t - toc (timerid)); + t += p; endfor unwind_protect_cleanup if (! isempty (oldfig)) @@ -100,5 +105,5 @@ %! title ("comet3() animation"); %! view (3); hold on; %! t = 0:pi/20:5*pi; -%! comet3 (cos (t), sin (t), t, 0.05); +%! comet3 (cos (t), sin (t), t); %! hold off;