ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Hans Hagen via ntg-context <ntg-context@ntg.nl>
To: Fabrice L via ntg-context <ntg-context@ntg.nl>
Cc: Hans Hagen <j.hagen@freedom.nl>
Subject: Re: Metafun : save memory content ?
Date: Mon, 18 Jul 2022 18:31:31 +0200	[thread overview]
Message-ID: <997fc361-3b3b-170c-d887-969db193c195@freedom.nl> (raw)
In-Reply-To: <76FE7288-1CE0-4548-AB1E-6A145C01C47C@gmail.com>

On 7/18/2022 3:20 PM, Fabrice L via ntg-context wrote:
> 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 ;
> endfor;
> 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 ;
> endfor;
> save the position of all objects ;
> 
> Etc...
> 
> 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 ?
there's always an idea ...

\starttext
     \startMPpage
         runscript("metapost.setparameterset('test', 
table.load('mydata.lua') or { })") ;
         path b ; b := getparameterpath "test" "test_c";
         draw fullcircle scaled 3cm ;
         draw b scaled .4;
       % show(b);
         getparameters "test" [
             test_a = 123,
             test_b = (456,789),
             test_c = (boundingbox currentpicture)
         ] ;
 
runscript("table.save('mydata.lua',(metapost.getparameterset('test')))") ;
     \stopMPpage
\stoptext

but maybe i need abetter one .. a proper save/restore in the tuc file or 
so, but you can play with this first

Hans


-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : https://contextgarden.net
___________________________________________________________________________________

  parent reply	other threads:[~2022-07-18 16:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-18 13:20 Fabrice L via ntg-context
2022-07-18 14:39 ` Henning Hraban Ramm via ntg-context
2022-07-18 15:45   ` Hans Hagen via ntg-context
2022-07-18 16:31 ` Hans Hagen via ntg-context [this message]
2022-07-18 17:53   ` Hans van der Meer via ntg-context
2022-07-19  3:28   ` Fabrice L via ntg-context
2022-07-19 11:42     ` Bruce Horrocks via ntg-context
2022-07-20  3:01       ` Fabrice L via ntg-context

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=997fc361-3b3b-170c-d887-969db193c195@freedom.nl \
    --to=ntg-context@ntg.nl \
    --cc=j.hagen@freedom.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).