Question: how to more efficiently collect frames for animations

To make animations, one must generate many plots. The following are two methods I know about. Which would be better? And is there a more efficient way than any of these?

This one pre-allocates an Array of the correct size needed, then fills it in in the loop. But then one has to convert the whole Array back to a list in order to animate it

restart;
nFrames := 10:
frames  := Array([seq(0,i=1..nFrames)]):
w       := 0:
for i from 1 to nFrames do
      frames[i] := plot(sin(w*t),t=-2*Pi..2*Pi);
      w         := w+1;
od:
plots:-display(convert(frames,list),insequence=true);

 

This method does not need to convert an Array to a list. But it does not pre-allocate memory needed before and has to dynamically grow the list each time, which might not be efficient

restart;
nFrames :=10:
frames  := NULL:
w       := 0:
for i from 1 to nFrames do
      frames := frames , plot(sin(w*t),t=-2*Pi..2*Pi);
      w      := w+1;
od:
plots:-display(frames,insequence=true);

For very large number of frames, I am not sure which is better. It is always best to pre-allocate memory to avoid dynamic growing list, which can be costly. But on the other hand, the first method requires converting the whole Array to a list, and I was not sure if that is done in-place or if Maple will have to copy the whole thing again to make a list.

Are there better and more efficient ways to do the above?

Please Wait...