ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Hans Hagen <j.hagen@xs4all.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>,
	Aditya Mahajan <adityam@umich.edu>
Subject: Re: simplifying repeated macro calls in metafun
Date: Thu, 24 Jun 2021 09:16:56 +0200	[thread overview]
Message-ID: <41b3e2c9-b63b-eb29-6ccc-af04b87e446f@xs4all.nl> (raw)
In-Reply-To: <nycvar.YAK.7.78.908.2106232341280.827465@nqv-guvaxcnq>

On 6/24/2021 5:42 AM, Aditya Mahajan wrote:
> On Wed, 23 Jun 2021, Aditya Mahajan wrote:
> 
>> On Thu, 24 Jun 2021, Jeong Dal wrote:
>>
>>> Now, I am trying to do the same thing using \startuseMPgraphic, but I don’t the correct result yet.
>>> Using \startuseMPgraphic, and \dorecurse, the code is simpler. But, it seems to me that \startanimation … \stopanimation is not working with \dorecurse{}{} …
>>> It just list all the graphics.
>>> Any hint is welcome.
>>
>> A while back, I wrote some code to easily generate metapost animations.
>>
>> https://adityam.github.io/context-blog/post/metapost-animation/
>>
>> I haven't used it much because I am mostly on linux, and its is a PITA to get an older version of Adobe Reader to work under wine.
> 
> Here's a version using these macros. It runs with MkIV but not with LMTX. Sorry, no time to debug what's going wrong in LMTX right now.
mp variable handling in lmtx is a bit more sophisticated

when we pass colors, numerics, dimensions there is some guess work going 
on wrt the type of the variable and on the average that works ok but in 
lmtx we can also fetch variables

so here is a basic setup for you (not much animation but it shows the idea

\unprotect

% this is similar to mkiv, although we add protection against
% overload; i should  still use the new argument handling here

\permanent\protected\def\startMPanimation
   {\dodoublegroupempty\meta_start_animation}

\permanent\protected\lettonothing\stopMPanimation

\def\meta_start_animation#1%
   {\normalexpanded{\meta_start_animation_indeed{#1}}}

\permanent\protected\def\meta_start_animation_indeed#1#2#3\stopMPanimation
 
{\gdefcsname\??mpgraphic#1\endcsname{\meta_handle_use_graphic{#1}{#2}{#3}}}

% this one is like yours too but it has more wrapping inside
% wrt namespace, picking up variables etc; as you can see,
% we just operate in the normal mp related variable namespace

\permanent\tolerant\protected\def\useMPanimation#=#*#=%
   {\meta_begin_graphic_group{#1}%
    \checkmpcategoryparent
    \let\currentmpcategory\currentMPgraphicname
    \setupcurrentmpcategory[#2]%
    \dorecurse{\mpcategoryparameter{n}}{%
       \letmpcategoryparameter{i}\recurselevel
       \begincsname\??mpgraphic#1\endcsname\empty
    }%
    \meta_end_graphic_group}

% so, the main thing here is that we added the loop and
% for convenience i store the current step

\protect

\starttext

\setupMPvariables
   [animation]
   [n=4]

% watch how we *pick up* a variable, no expansion mess, we
% avoid heuristics, it might even be faster (not that it
% matters because tex is already pretty fast)

\startMPanimation{circle}
     fill fullcircle scaled (10cm / mpvarn("i"));
\stopMPanimation

% there currently are mpvarn, mpvard, mpvars, mpvarb

\useMPanimation{circle}{n=4}

\stoptext



-----------------------------------------------------------------
                                           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 / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

  reply	other threads:[~2021-06-24  7:16 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.1145.1624377609.1130.ntg-context@ntg.nl>
2021-06-23 20:26 ` Jeong Dal
2021-06-24  3:31   ` Aditya Mahajan
2021-06-24  3:42     ` Aditya Mahajan
2021-06-24  7:16       ` Hans Hagen [this message]
     [not found] <mailman.47.1624523134.1143.ntg-context@ntg.nl>
2021-06-25 19:14 ` Jeong Dal
     [not found] <mailman.1069.1624285904.1130.ntg-context@ntg.nl>
2021-06-21 21:50 ` Jeong Dal
2021-06-22 13:49   ` Otared Kavian
2021-06-22 16:00     ` Wolfgang Schuster
     [not found] <mailman.1.1624183201.7245.ntg-context@ntg.nl>
2021-06-20 23:30 ` Jeong Dal
2021-06-21  4:26   ` Aditya Mahajan
2021-06-21 12:07     ` Otared Kavian
2021-06-21 12:21       ` Mikael Sundqvist
2021-06-21 14:31         ` Otared Kavian
2021-06-21 18:35           ` Mikael Sundqvist
2021-06-21 13:34 ` Jeong Dal

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=41b3e2c9-b63b-eb29-6ccc-af04b87e446f@xs4all.nl \
    --to=j.hagen@xs4all.nl \
    --cc=adityam@umich.edu \
    --cc=ntg-context@ntg.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).