[NTG-context] MetaPost Animations

Wolfgang Schuster wolfgang.schuster at gmail.com
Tue Jan 1 08:48:48 CET 2013


Am 01.01.2013 um 04:50 schrieb Jeong Dal <haksan at me.com>:

> Dear Wolfgang,
> 
> Thank you for the explanation, and your sample works nicely.
> 
> I  enclosed \processMPbuffer using \startframe and \stopframe as following.
> Then  I got a 'undefined control sequence' error.
> If I use '\framed[]' instead of '\startframe … \stopframe', then it gave all 7 circles of different radius in two pages without error.
> If I add "\startanimation … \stopanimation", the only change is the appearance of menu at the bottom of the last circle.(no animation)
> 
> What is wrong in the code?

1. The \frame and \startframe commands are only available *in* the animation environment where they are locally defined.

2. Although \framed sound similar to \frame there is no relation between both commands.

3. You have to expand the loop value *before* it is passed to metapost, see below.

\usemodule[animation]
\setupinteraction[state=start]

\startuseMPgraphic{circles}{counter}
	path p;
	numeric n, u;
	u := 1cm;
	n:=\MPvar{counter}*u;
	p := fullcircle scaled n;
	draw p;
\stopuseMPgraphic

\starttext
\startanimation[menu=yes]
\dorecurse{7}{%
	\startframe
	\useMPgraphic{circles}{counter=#1}%
	\stopframe}
\stopanimation
\stoptext

4. You can also include the metapost code in the frame but you have to expand the \recurselevel value with the \expanded command (I have to upload a new version of the module first because \startframe isn’t expandable yet).

\usemodule[animation]
\setupinteraction[state=start]

\starttext
\startanimation[menu=yes]
\dorecurse{7}{\expanded
   {\startframe
    \startMPcode
    path p;
    numeric n, u;
    u := 1cm;
    n:=\recurselevel*u;
    p := fullcircle scaled n;
    draw p;
    \stopMPcode
    \stopframe}}
\stopanimation
\stoptext

5. Use a PDF viewer with javascript support (e.g. Adobe Reader) to view the animation.

Kind regards and a happy new year,
Wolfgang


More information about the ntg-context mailing list