I am trying to create an animation in ConTeXt + MetaPost. In particular, I would like to have ConTeXt + MetaPost generate each individual frame of the animation, and then I would like to place each of these graphics on the page in succession. I am looking for a "ConTeXt way" without placing the MetaPost code in a separate source file, running MetaPost, and using \externalfigure. The following MetaPost sample code generate 21 graphics images (numbered .0 to .20), but I have no idea how to have ConTeXt generate these graphics without a manual external MetaPost run and have them included in a way that is consistent with \startuseMPgraphic or similar. Thanks in advance, Troy Henderson path p,q; p:=fullcircle scaled 72; L:=length p; N:=20; for n=0 upto N: beginfig(n); q:=subpath (0,n/N*L) of p; draw q withcolor red; fill fullcircle scaled 3 shifted point length q of q withcolor blue; setbounds currentpicture to unitsquare shifted (-0.5,-0.5) scaled 75; endfig; endfor; end -- Troy Henderson Assistant Professor Department of Mathematics University of Mobile http://www.tlhiv.org
Hi Troy
Here is a simple solution:
\def\MyGraphics#1{%
\startMPcode
path p,q;
p:=fullcircle scaled 72;
L:=length p;
N:=20;
q:=subpath (0,#1/N*L) of p;
draw q withcolor red;
fill fullcircle scaled 3 shifted point length q of q withcolor blue;
setbounds currentpicture to unitsquare shifted (-0.5,-0.5) scaled 75;
\stopMPcode}
\starttext
\dostepwiserecurse{0}{20}{1}{%
\startTEXpage
\MyGraphics{\recurselevel}
\stopTEXpage}
\stoptext
Regards, Bostjan
On Thu, Apr 15, 2010 at 7:53 PM, Troy Henderson
I am trying to create an animation in ConTeXt + MetaPost. In particular, I would like to have ConTeXt + MetaPost generate each individual frame of the animation, and then I would like to place each of these graphics on the page in succession. I am looking for a "ConTeXt way" without placing the MetaPost code in a separate source file, running MetaPost, and using \externalfigure. The following MetaPost sample code generate 21 graphics images (numbered .0 to .20), but I have no idea how to have ConTeXt generate these graphics without a manual external MetaPost run and have them included in a way that is consistent with \startuseMPgraphic or similar.
Thanks in advance,
Troy Henderson
path p,q; p:=fullcircle scaled 72; L:=length p; N:=20; for n=0 upto N: beginfig(n); q:=subpath (0,n/N*L) of p; draw q withcolor red; fill fullcircle scaled 3 shifted point length q of q withcolor blue; setbounds currentpicture to unitsquare shifted (-0.5,-0.5) scaled 75; endfig; endfor; end
-- Troy Henderson Assistant Professor Department of Mathematics University of Mobile http://www.tlhiv.org
___________________________________________________________________________________ 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://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net
___________________________________________________________________________________
On 16-4-2010 9:36, Boštjan Vesnicer wrote:
Hi Troy
Here is a simple solution:
\def\MyGraphics#1{% \startMPcode path p,q; p:=fullcircle scaled 72; L:=length p; N:=20; q:=subpath (0,#1/N*L) of p; draw q withcolor red; fill fullcircle scaled 3 shifted point length q of q withcolor blue; setbounds currentpicture to unitsquare shifted (-0.5,-0.5) scaled 75; \stopMPcode}
\starttext \dostepwiserecurse{0}{20}{1}{% \startTEXpage \MyGraphics{\recurselevel} \stopTEXpage} \stoptext
or, if you want to fool yourself that you're not using tex ... put this in "somefile.cld": -- -- local template = [[ path p, q ; p := fullcircle scaled 72 ; L := length p ; N := 20 ; q:=subpath (0,%s/N*L) of p ; draw q withcolor red ; fill fullcircle scaled 3 shifted point length q of q withcolor blue ; setbounds currentpicture to unitsquare shifted (-0.5,-0.5) scaled 75 ; ]] context.starttext() for i=0,20 do context.startMPpage() context(template,i) context.stopMPpage() end context.stoptext() -- -- and then run: context somefile.cld ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
\def\MyGraphics#1{%
Thanks for the replies folks. The example that I posted is a simple example. The example that I'm working on (displaying successive terms in a Taylor series) requires a bit of computations, and I don't want to have to go back and do each computation for each value of #1. That is, I want to build a table of numerical values (numeric Y[][]) and be able to address those values from my \startMPcode section. If I have two different \startMPcode ... \stopMPcode sections, is there a way (perhaps it does this by default) to have the variables stored in the first block available in the second block? In pure MetaPost, I can do numeric a:=4; beginfig(1); label(decimal(a),origin); endfig; beginfig(2); label(decimal(a),origin); endfig; end and both figures have the value of 'a' available to them because 'a' was defined before each figure. What is the ConTeXt way of doing this? Thanks, Troy
If I have two different \startMPcode ... \stopMPcode sections, is there a way (perhaps it does this by default) to have the variables stored in the first block available in the second block? In pure MetaPost, I can do
numeric a:=4; beginfig(1); label(decimal(a),origin); endfig; beginfig(2); label(decimal(a),origin); endfig; end
and both figures have the value of 'a' available to them because 'a' was defined before each figure. What is the ConTeXt way of doing this?
Do you mean something like this? \starttext \startMPpage a := 4; label(decimal a, origin); \stopMPpage \startMPpage a := a+1; label(decimal a, origin); \stopMPpage \stoptext Regards, Bostjan
Am 16.04.10 14:51, schrieb Troy Henderson:
If I have two different \startMPcode ... \stopMPcode sections, is there a way (perhaps it does this by default) to have the variables stored in the first block available in the second block? In pure MetaPost, I can do
numeric a:=4; beginfig(1); label(decimal(a),origin); endfig; beginfig(2); label(decimal(a),origin); endfig; end
and both figures have the value of 'a' available to them because 'a' was defined before each figure. What is the ConTeXt way of doing this?
\starttext \startluacode local a = 0 for i=1,10 do a = a + 1 context.startMPpage() -- context('label("%d",origin);',a) context('label(textext("%d"),origin);',a) context.stopMPpage() end \stopluacode \stoptext Wolfgang
participants (4)
-
Boštjan Vesnicer
-
Hans Hagen
-
Troy Henderson
-
Wolfgang Schuster