Re: How do I generate an animated pdf file from xfig/metapost



I personally create the frames using MetaPost. MetaPost is a
programming language, and therefore you can generate the frames
dynamically. I will post the source code below for an animation that
I've done which illustrates how an ellipse is constructed. Just save
the code in, say, ellipse.mp and then run `mpost ellipse.mp` on the
source. After the graphics are constructed, MetaPost will instruct
you to run `pdflatex ellipse.ltx`. Execute it as it says, and your
output should be ellipse.pdf. This PDF will have each frame of the
animation on its own page, and therefore should be easy to use with
animations packages from CTAN.

I apologize in advance for the long post, but the code is written for
readability and not for conciseness.

Troy

%%% Here's the code %%%

c:=2/(1+sqrt(5)); % Ratio of "y-radius" to "x-radius" (should be
positive)
N:=64; % Number of frames in the animation
T:=4; % Approximate time (in seconds) to complete an animation cycle
u:=136; % Maximum height/width of ellipse (in PostScript points)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Here's the magic %%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%
pair f;
if c<1: f:=(1+-+c,0); v:=u/2; else: f:=(0,1+-+(1/c)); v:=u/c/2; fi; %
Focus f is defined
path p,q;
picture base;
beginfig(0);
p:=fullcircle yscaled c; % This is the ellipse
draw p scaled (2*v) withpen pencircle scaled (v/260) dashed evenly; %
Draw the ellipse dashed (will be traced later)
input mp-tool;
q:=bbox currentpicture enlarged (v/64); % Enlarge the bounding box
slightly
fill fullcircle scaled (v/32) shifted (f*v) withcolor red; % Focus
fill fullcircle scaled (v/32) shifted (-f*v) withcolor red; % Focus
base:=currentpicture; % Save this picture to draw in every frame
setbounds currentpicture to q; % Set the bounding box as described
before
endfig;
W:=ceiling(xpart urcorner q - xpart llcorner q)+1; % The width to pass
to LaTeX
H:=ceiling(ypart urcorner q - ypart llcorner q)+1; % The height to
pass to LaTeX

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%
% Create a LaTeX file which will contain each frame of the animation
on its own page %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%
write "\documentclass{minimal}" to jobname & ".ltx";
write "\usepackage[paperwidth=" & decimal(W) & "bp,paperheight=" &
decimal(H) & "bp,margin=0bp,noheadfoot]{geometry}" to jobname &
".ltx";
write "\usepackage{graphicx}" to jobname & ".ltx";
write "\usepackage{ifpdf}\ifpdf\DeclareGraphicsRule{*}{mps}{*}{}\fi"
to jobname & ".ltx";
write "\usepackage[pdfstartview=Fit,bookmarks=false]{hyperref}" to
jobname & ".ltx";
write "\begin{document}" to jobname & ".ltx";
write "\noindent\includegraphics{" & jobname & ".0}\clearpage" to
jobname & ".ltx";

L:=length p; % Length (in "time") of the ellipse curve
pair z;
for n=1 upto (N-1): % Generate each frame of the animation
beginfig(n);
fill q withcolor 0.99*white;
draw base; % Draw the common picture saved above
draw subpath (0,(n-1)/(N-1)*L) of p scaled (2*v) withpen pencircle
scaled (v/130) withcolor blue; % Trace the ellipse in blue
z:=point ((n-1)/(N-1)*L) of p scaled v; % The point on the ellipse
where we are thusfar
fill fullcircle scaled (v/32) shifted (2*z) withcolor blue; % Draw
the point
draw (-f*v)--(2*z)--(f*v) withpen pencircle scaled (v/260); % Draw
the string used to trace the ellipse
setbounds currentpicture to q; % Set the bounding box so that it is
the same for each frame
endfig;
write "\noindent\includegraphics{" & jobname & "." & decimal(n) & "}
\clearpage" to jobname & ".ltx"; % Update LaTeX file
endfor;
write "\end{document}" to jobname & ".ltx"; % Finish up the LaTeX file

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Inform the user what to do now %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
message " ";
message "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%";
message "Execute the following commands to generate the animation:";
message " ";
message "pdflatex " & jobname & ".ltx";
message " ";
message "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%";
message " ";

end

.



Relevant Pages

  • Re: Fade into a Picture Box or Image Control
    ... Joe users old P3 only manages to draw a couple of frames a second and the same animation takes forever. ... Dim StartTime As Long, EndTime As Long, TimeNow As Long ... Where DrawFrame() draw the frame at the given opacity, I prefer doing this rather than cluttering the animation loop ...
    (microsoft.public.vb.winapi.graphics)
  • Re: Sagnac Threads United
    ... I've made minor internal changes to my animation. ... My animation is NOW for a large rotating ring. ... nature of those 'apparent' motions in YOUR ROTATING frame. ...
    (sci.physics.relativity)
  • Re: animation with static background image`
    ... has no effect on the appearance of the next frame. ... Draw the background, ... which effectively wipes out all trace of the previous frame, ... Animation should have play/pause option. ...
    (comp.lang.java.programmer)
  • Re: How do I generate an animated pdf file from xfig/metapost
    ... I will post the source code below for an animation that ... I've done which illustrates how an ellipse is constructed. ... This PDF will have each frame of the ... Draw the ellipse dashed ...
    (comp.text.tex)
  • Re: Flashing a sprite
    ... you've reached the end of the animation, in which case frameIndex would go ... I guess the 2 would be my amount of seconds....but after gametime ... frames display frame 0, x amount of frames display frame 1" etc... ... you could just make a 2-frame animation for your flashing sprite. ...
    (microsoft.public.win32.programmer.directx.managed)