# HG changeset patch # User Rik # Date 1375742642 25200 # Node ID c954b0a396a2bed0cfefe5f00046db766d45ec1d # Parent 6992c1bb4773aac83d6930f5ac03e3f08556de12 comet.m: Speed up animation by using low-level graphic commands. * scripts/plot/comet.m: Speed up animation by using low-level graphic commands. diff -r 6992c1bb4773 -r c954b0a396a2 scripts/plot/comet.m --- a/scripts/plot/comet.m Mon Aug 05 14:18:50 2013 -0700 +++ b/scripts/plot/comet.m Mon Aug 05 15:44:02 2013 -0700 @@ -63,15 +63,23 @@ limits = [min(x), max(x), min(y), max(y)]; num = numel (y); dn = round (num/10); - for n = 1:(num+dn); + + hl = plot (x(1), y(1), "color", "r", "marker", "none", + x(1), y(1), "color", "g", "marker", "none", + x(1), y(1), "color", "b", "marker", "o"); + axis (limits); # set manual limits to speed up plotting + + for n = 2:(num+dn); m = n - dn; m = max ([m, 1]); k = min ([n, num]); - plot (x(1:m), y(1:m), "r", x(m:k), y(m:k), "g", x(k), y(k), "ob"); - axis (limits); + set (hl(1), "xdata", x(1:m), "ydata", y(1:m)); + set (hl(2), "xdata", x(m:k), "ydata", y(m:k)); + set (hl(3), "xdata", x(k), "ydata", y(k)); drawnow (); pause (p); endfor + unwind_protect_cleanup if (! isempty (oldfig)) set (0, "currentfigure", oldfig); @@ -86,5 +94,5 @@ %! t = 0:.1:2*pi; %! x = cos (2*t) .* (cos (t).^2); %! y = sin (2*t) .* (sin (t).^2); -%! comet (x, y); +%! comet (x, y, 0.05);