[latex]在beamer中使用tikz和animate宏包绘制PDF动画的示例

33 篇文章 3 订阅
17 篇文章 0 订阅
本文提供了一个在Beamer中使用TikZ和Animate宏包绘制PDF动画的示例,具体展示了如何在传热学课件中创建动画效果。包括坐标轴绘制、金属壁面和保温层的划分以及点标注等步骤,最终生成了动态展示过程的动画。
摘要由CSDN通过智能技术生成

[latex]在beamer中使用tikz和animate宏包绘制PDF动画的示例.

下面是我在做传热学课件的时候,写的代码,供大家参考:

文件名:图3-2.tex.

\tiny{%  
\begin{animateinline}[autoplay,poster=last,loop,    
     begin={\begin{tikzpicture}[scale=1,line width=0.7pt]    
            \useasboundingbox (-0.5cm,-1cm) rectangle(6.5cm,5.5cm);
%画坐标轴四个端点
\coordinate (p1) at (-0.25,0);%
\coordinate[label=below:$x$] (p2) at (6,0);%
\coordinate (p3) at (0,-0.25);%
\coordinate[label=left:$y$] (p4) at (0,5.4);%
\draw [->,name path = xaxisline](p1)--(p2);
\draw [->,name path = yaxisline](p3)--(p4);
\node[below left,name intersections={of=xaxisline and yaxisline, by=po}] (po) at (po){$O$};
%画金属壁面
\coordinate [label=below:$A$](A) at (0.5,0.5);%
\coordinate (p5) at (3,5);%
\draw  (A) rectangle (p5);
\node at ($(p5)+(-1.5,-0.25)$){ 金属壁};
%画保温层
\coordinate [label=below:$L$](L) at (5.5,0.5);%
\coordinate [label=below:$L_0$](L0) at ($(A)!(p5)!(L)$);%角点
\draw  (p5) rectangle (L);
\node at ($(p5)+(+1.5,-0.25)$){ 保温层};
%
%标注pABCDEFGHIJKLMN点
\coordinate[label=135:$P$] (P) at ($(A)+(0,4)$);%
\coordinate[label=left:$t_1$] (t1) at ($(P)+(-0.5,0)$);%
\coordinate[label=left:$t_0$] (t0) at ($(A)+(-0.5,0)$);%
\coordinate[label=below:$B$] (B) at ($(A)+(0.5,0)$);%
\coordinate[label=below:$C$] (C) at ($(A)+(1.5,0)$);%
\coordinate[label=225:$D$] (D) at ($(p5)+(0,-3)$);%
\coordinate[label=225:$E$] (E) at ($(p5)+(0,-2)$);%
\coordinate[label=225:$F$] (F) at ($(p5)+(0,-1.4)$);%
\coordinate[label=left:$G$] (G) at ($(p5)+(0,-1)$);%
\coordinate[label=135:$H$] (H) at ($(p5)+(0,-0.75)$);%
\coordinate[label=below:$I$] (I) at ($(L0)+(0.4,0)$);%
\coordinate[label=below:$J$] (J) at ($(L0)+(1.0,0)$);%
\coordinate[label=below:$K$] (K) at ($(L0)+(1.7,0)$);%
\coordinate[label=right:$M$] (M) at ($(L)+(0,1)$);%
%
\draw[dashed] (t1)--(P);
\draw[dashed] (t0)--(A);
%金属壁面划线 保温层划线
\begin{scope}[dashed,green!80,line width=0.5pt]
%\draw(P)--(A); 
\draw(P)..controls  ($ (P)!.7! -5:(B) $) and ($ (B)!.3! 15:(P) $)..(B); 
\draw(P)..controls  ($ (P)!.7! -10:(C) $) and ($ (C)!.2! 25:(P) $)..(C); 
\draw(P)..controls  ($ (P)!.7! -10:(L0) $) and ($ (L0)!.2! 25:(P) $)..(L0);
%
\draw(P)..controls  ($ (P)!.75! -10:(D) $) and ($ (D)!.2! 25:(P) $)..(D);
\draw(D)..controls  ($ (D)!.5! -15:(I) $) and ($ (I)!.3! 15:(D) $)..(I);   
\draw(P)..controls  ($ (P)!.7! -5:(E) $) and ($ (E)!.3! 15:(P) $)..(E);
\draw(E)..controls  ($ (E)!.6! -10:(J) $) and ($ (J)!.3! 10:(E) $)..(J); 
\draw(P)..controls  ($ (P)!.6! -5:(F) $) and ($ (F)!.3! 10:(P) $)..(F); 
\draw(F)..controls  ($ (F)!.5! -15:(K) $) and ($ (K)!.3! 15:(F) $)..(K);  
\draw(P)..controls  ($ (P)!.5! -5:(G) $) and ($ (G)!.3! 5:(P) $)..(G);
\draw(G)..controls  ($ (G)!.6! -10:(L) $) and ($ (L)!.3! 10:(G) $)..(L);  
\draw(P)..controls  ($ (P)!.5! 0:(H) $) and ($ (H)!.3! 0:(P) $)..(H); 
\draw(H)..controls  ($ (H)!.6! -5:(M) $) and ($ (M)!.3! 5:(H) $)..(M);
\end{scope}
\node at(3,-0.65){\small 图3-2:~非稳态导热过程中复合壁温度的变化};
},    
     end={\end{tikzpicture}}]{1}%  
%总共生成7帧画面,以每秒1帧的速度自动播放
%金属壁面划线 保温层划线
\draw[red,line width=1.5pt] (P)--(A)--(L);\newframe %0
\draw[red,line width=1.5pt] (P)..controls  ($ (P)!.7! -5:(B) $) and ($ (B)!.3! 15:(P) $)..(B)--(L);\newframe %0
\draw[red,line width=1.5pt] (P)..controls  ($ (P)!.7! -10:(C) $) and ($ (C)!.2! 25:(P) $)..(C)--(L);\newframe %1
\draw[red,line width=1.5pt] (P)..controls  ($ (P)!.7! -10:(L0) $) and ($ (L0)!.2! 25:(P) $)..(L0)--(L);\newframe %2
%
\draw[red,line width=1.5pt] (P)..controls  ($ (P)!.75! -10:(D) $) and ($ (D)!.2! 25:(P) $)..(D);
\draw[red,line width=1.5pt] (D)..controls  ($ (D)!.5! -15:(I) $) and ($ (I)!.3! 15:(D) $)..(I)--(L); \newframe %3 
\draw[red,line width=1.5pt] (P)..controls  ($ (P)!.7! -5:(E) $) and ($ (E)!.3! 15:(P) $)..(E);
\draw[red,line width=1.5pt] (E)..controls  ($ (E)!.6! -10:(J) $) and ($ (J)!.3! 10:(E) $)..(J)--(L);\newframe %4 
\draw[red,line width=1.5pt] (P)..controls  ($ (P)!.6! -5:(F) $) and ($ (F)!.3! 10:(P) $)..(F); 
\draw[red,line width=1.5pt] (F)..controls  ($ (F)!.5! -15:(K) $) and ($ (K)!.3! 15:(F) $)..(K)--(L);\newframe %5 
\draw[red,line width=1.5pt] (P)..controls  ($ (P)!.5! -5:(G) $) and ($ (G)!.3! 5:(P) $)..(G);
\draw[red,line width=1.5pt] (G)..controls  ($ (G)!.6! -10:(L) $) and ($ (L)!.3! 10:(G) $)..(L);\newframe %6 
\draw[red,line width=1.5pt] (P)..controls  ($ (P)!.5! 0:(H) $) and ($ (H)!.3! 0:(P) $)..(H); 
\draw[red,line width=1.5pt] (H)..controls  ($ (H)!.6! -5:(M) $) and ($ (M)!.3! 5:(H) $)..(M)--(L);

\end{animateinline}
}%  
测试程序main.tex如下:

\documentclass{beamer}
\input{preamble.tex}  %包含所有必须的宏包等等
\input{tikzall.tex} %包含所有的tikz包
\begin{document}
\begin{frame}[t]
\input{图3-2.tex}
\end{frame}

\end{document} 
编译命令:

xelatex -shell-escape main
xelatex -shell-escape main

生成的PDF文件中红色的线会动画显示,效果如下:



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值