Re: How do I generate an animated pdf file from xfig/metapost
- From: MMasroorAli <mmasroorali@xxxxxxxxxxxxxx>
- Date: 4 May 2007 08:02:39 -0700
On May 4, 8:35 pm, tlhiv <thend...@xxxxxxxxx> wrote:
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
Thanks a lot for the infomative post.
Is there a GUI tool to for an easier approach for drawing the graphics
(if xfig is not suitable)?
.
- Follow-Ups:
- References:
- How do I generate an animated pdf file from xfig/metapost
- From: MMasroorAli
- Re: How do I generate an animated pdf file from xfig/metapost
- From: tlhiv
- How do I generate an animated pdf file from xfig/metapost
- Prev by Date: Re: How do I generate an animated pdf file from xfig/metapost
- Next by Date: Re: How do I generate an animated pdf file from xfig/metapost
- Previous by thread: Re: How do I generate an animated pdf file from xfig/metapost
- Next by thread: Re: How do I generate an animated pdf file from xfig/metapost
- Index(es):
Relevant Pages
|