[NTG-context] Metafun : save memory content ?

Fabrice L fabrice.alpha at gmail.com
Mon Jul 18 15:20:30 CEST 2022

Dear list,

I’m doing animations in MetaFun, by simply using \startMPpage (…) \stopMPpage for each frame of the animation. Here is an example: https://youtu.be/yhxUbVQx9Uo (please note you can watch it in HD by adjusting the setting in YouTube).

This works usually great, but when the number of objects to draw by page is large, the resulting pdf file could be huge, several gigabytes sometimes. Such huge files are difficult (sometimes impossible) to convert in jpeg files (I’m using Image magick for the conversion), necessary to do a mp4 movie. 

One solution is to do several pdf files, for example one by second; with this option, I can do 60 files of 30 pages, for an animation of 60 seconds (1800 frames for 1 minute). Everything is smoother this way, quicker to convert files. But in order to do so, I have to be able to describe each frame of the animation with the same set of instructions; so the position of an object at time t is described by an equation for example.

But this is not always possible. If the animation is based on a random process, the position of an object at time t depends on his position at time t-1. I can still use this preceeding strategy by simulating the past at the begging of each second, starting with a unique random seed. So for example if I work on second 9, I begin by calculating the past from frame 1 to frame 240 (8*30) and then simulate time 241, draw frame 241, simulate time 242, draw time 242, etc.. This could be complicated to do, but is feasible. The drawback is that more I advance in time, the more computations I have to do at the beginning of each file. 

So to simplify things, one option would be to be save the state of some variables at some point in time, say t, in order to be able to access these informations at time t+1. So the strategy would be :

% File second1.pdf
for frame =1 to 30 :
	simulate position of objects ;
	draw the frame ;
save the position of all objects ;

% File second2.pdf
Read (access) the position of all objects from second 1(after frame 30);
for frame =31 to 60 :
	simulate position of objects ;
	draw the frame ;
save the position of all objects ;


Does someone has an idea of how to do such a thing ? I can read text file in Context with no problem and integrate them in the animation process with \startMPinclusions (…) \stopMPinclusions, but I did not find a way to write information from MetaFun to a text file. Is Lua the solution ? 

Thanks for any help !

More information about the ntg-context mailing list