8

I have this MetaPost input file:

%@ Maxime Chupin
%@ 4 février 2017
%@ animCercle.mp

prologues := 3;
outputtemplate := "svg/%j-%c.svg";
outputformat := "svg";

% unité
u:=1cm;
%rayon cercle
r:=5u;

% nombre de quartier
numeric n;
n := 16;

% l'origine
pair O;
O :=(0,0);


% le fond
picture fond;
numeric angle;
fond = image(
  fill fullcircle scaled 2r withcolor black;
  for i:= 0 upto n-1:
  angle := (360.0/n)*i;
  draw (-r*cosd(angle),-r*sind(angle)) -- (r*cosd(angle),r*sind(angle)) withcolor white;
endfor;
);

% les balles
% rayon balle
rb := 0.3u;
def balle =
  fullcircle scaled 2rb
enddef;

% les différentes images
for j:= 0 upto 359:
  beginfig(j);
    draw fond;
    for i:=0 upto n-1:
      angle := (360.0/n)*i;
      fill balle shifted ((r-rb)*sind(angle+j),0) rotatedaround(O,angle) withcolor white;
    endfor;
  endfig;
endfor;
end.

As is, it produces a set of numbered SVG files if I run mptopdf on it. Now I want mptopdf to output multipage PDF with one animation frame per page.

Is that possible without writing a wrapper (La)TeX file?

I want to use the PDF as input for building a standalone animated SVG, using the animate package.

For output in PDF format I modified the following lines of the input file:

%outputtemplate := "svg/%j-%c.svg";
%outputformat := "svg";
outputformat := "pdf";

Currently, I only get a set of numbered PDF files.

3
  • “Is that possible without writing a wrapper (La)TeX file?” You are aware the mptopdf actually calls TeX? Jan 29, 2019 at 2:50
  • No, I was not. Mpost yes, but TeX not.
    – AlexG
    Jan 29, 2019 at 5:32
  • 1
    Well yes, it does. mptopdf is just a short Perl script which calls pdftex with the format specified by mptopdf.tex. Jan 29, 2019 at 5:39

1 Answer 1

6

You can use the mptopdf.tex format to implement your own version of mptopdf. First I process your MetaPost file with mpost. Here the full file again for reference.

%@ Maxime Chupin
%@ 4 février 2017
%@ animCercle.mp

prologues := 3;
%outputtemplate := "svg/%j-%c.svg";
%outputformat := "svg";
outputformat := "pdf";

% unité
u:=1cm;
%rayon cercle
r:=5u;

% nombre de quartier
numeric n;
n := 16;

% l'origine
pair O;
O :=(0,0);


% le fond
picture fond;
numeric angle;
fond = image(
  fill fullcircle scaled 2r withcolor black;
  for i:= 0 upto n-1:
  angle := (360.0/n)*i;
  draw (-r*cosd(angle),-r*sind(angle)) -- (r*cosd(angle),r*sind(angle)) withcolor white;
endfor;
);

% les balles
% rayon balle
rb := 0.3u;
def balle =
  fullcircle scaled 2rb
enddef;

% les différentes images
for j:= 0 upto 359:
  beginfig(j);
    draw fond;
    for i:=0 upto n-1:
      angle := (360.0/n)*i;
      fill balle shifted ((r-rb)*sind(angle+j),0) rotatedaround(O,angle) withcolor white;
    endfor;
  endfig;
endfor;
end.

This gives me files test.<n> where n is a number between 0 and 359. Then I use the following TeX file to process everything into one single PDF document.

test.tex

% mptopdf uses \everypar to scan arguments.  Clear it.
\everypar{}

% \processMPfile uses \bye but we only want \eject
\def\bye{\eject}

% The argument of \processMPfile is delimited by space which is really
% inconvenient at times.  Make it well behaved instead.
\def\MPpage#1{\processMPfile #1 }

% Loop over all the MP files
\count0=0
\loop\ifnum\count0<360
  \MPpage{test.\the\count0}
  \advance\count0 by 1
\repeat

\end

The file is processed with pdftex --fmt=mptopdf test.tex.

Then I converted the resulting PDF to an animated GIF.

convert -density 40 test.pdf -delay 1 -loop 0 -background white -alpha remove test.gif

enter image description here

1
  • \pdfinfo seems not to work here. Is there a simple way to add some info ? Dec 28, 2020 at 17:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .