我想创建一个幻灯片来展示剪辑的工作原理,如下面的动画所示。
我使用了两个框架,最后一个框架是必需的,因为我想隐藏前几张幻灯片裁剪区域中不需要的(修剪过的)部分。我想避免使用两个框架并重复代码。
我们可以强制beamer
延迟剪辑代码并隐藏之前的绘画吗?我是新手beamer
,只知道\pause
。:-)
\documentclass{beamer}
\usepackage{pstricks-add}
\usepackage[active,tightpage]{preview}
\PreviewBorder=0pt
\PreviewEnvironment{pspicture}
\begin{document}
\begin{frame}
\begin{pspicture}(6,6)
\pnode(0,0){A}
\pnode(6,0){B}
\pnode(6,6){C}
\pnode(0,6){D}
\pnode(1,1){P}
\pnode(5,1){Q}
\pnode(3,5){R}
\pspolygon*[linecolor=red](A)(B)(Q)(P)\pause
\pspolygon*[linecolor=green](B)(C)(R)(Q)\pause
\pspolygon*[linecolor=blue](C)(D)(R)\pause
\pspolygon*[linecolor=yellow](D)(A)(P)(R)
\end{pspicture}
\end{frame}
\begin{frame}
\begin{pspicture}(6,6)
\pnode(0,0){A}
\pnode(6,0){B}
\pnode(6,6){C}
\pnode(0,6){D}
\pnode(1,1){P}
\pnode(5,1){Q}
\pnode(3,5){R}
\psclip{\pscircle[linestyle=none,dimen=middle](3,3){3}}
\pspolygon*[linecolor=red](A)(B)(Q)(P)
\pspolygon*[linecolor=green](B)(C)(R)(Q)
\pspolygon*[linecolor=blue](C)(D)(R)
\pspolygon*[linecolor=yellow](D)(A)(P)(R)
\endpsclip
\end{pspicture}
\end{frame}
\end{document}
答案1
您可以使用\only
或\onslide
;例如\only
:
\documentclass{beamer}
\usepackage{pstricks-add}
\usepackage[active,tightpage]{preview}
\PreviewBorder=0pt
\PreviewEnvironment{pspicture}
\begin{document}
\begin{frame}
\begin{pspicture}(6,6)
\pnode(0,0){A}
\pnode(6,0){B}
\pnode(6,6){C}
\pnode(0,6){D}
\pnode(1,1){P}
\pnode(5,1){Q}
\pnode(3,5){R}
\only<5>{\psclip{\pscircle[linestyle=none,dimen=middle](3,3){3}}}
\only<1->{\pspolygon*[linecolor=red](A)(B)(Q)(P)}
\only<2->{\pspolygon*[linecolor=green](B)(C)(R)(Q)}
\only<3->{\pspolygon*[linecolor=blue](C)(D)(R)}
\only<4->{\pspolygon*[linecolor=yellow](D)(A)(P)(R)}
\only<5>{\endpsclip}
\end{pspicture}
\end{frame}
\end{document}
编辑:
得到多页 PDF 之后,我们还可以利用它来制作 PDF 动画、GIF 动画和 PNG 图像。将以下内容用 TeX 处理pdflatex --shell-escape
。图像魔术师必须安装在您的计算机上。
\documentclass[preview,border=0pt]{standalone}
\usepackage{filecontents}
\begin{filecontents*}{dummy.tex}
\documentclass[serif]{beamer}
\usepackage{pstricks-add}
\usepackage[active,tightpage]{preview}
\PreviewBorder=0pt
\PreviewEnvironment{pspicture}
\begin{document}
\begin{frame}
\begin{pspicture}(6,6)
\pnode(0,0){A}
\pnode(6,0){B}
\pnode(6,6){C}
\pnode(0,6){D}
\pnode(1,1){P}
\pnode(5,1){Q}
\pnode(3,5){R}
\only<5>{\psclip{\pscircle[linestyle=none,dimen=middle](3,3){3}}}
\only<1->{\pspolygon*[linecolor=red](A)(B)(Q)(P)}
\only<2->{\pspolygon*[linecolor=green](B)(C)(R)(Q)}
\only<3->{\pspolygon*[linecolor=blue](C)(D)(R)}
\only<4->{\pspolygon*[linecolor=yellow](D)(A)(P)(R)}
\only<5>{\endpsclip}
\end{pspicture}
\end{frame}
\end{document}
\end{filecontents*}
\usepackage{animate}
\begin{document}
% create PDF
\immediate\write18{latex dummy}
\immediate\write18{dvips dummy}
\immediate\write18{ps2pdf dummy.ps}
% convert to GIF animation
\immediate\write18{convert -delay 100 -loop 0 -density 200 -alpha remove dummy.pdf \jobname.gif}
% convert to PNG
\makeatletter
\immediate\write18{convert -density 200 -alpha remove dummy.pdf \jobname-\@percentchar02d.png}
\makeatother
% create PDF animation
\begin{preview}
\animategraphics[controls]{2}{dummy}{}{}
\end{preview}
\end{document}
答案2
您可以使用 TikZ(它已经与 Beamer 集成得相当好),然后执行以下操作:
\begin{frame}
\begin{tikzpicture}
\clip<5> (3,3) circle (3);
\node [coordinate] (A) at (0,0) {};
\node [coordinate] (B) at (6,0) {};
\node [coordinate] (C) at (6,6) {};
\node [coordinate] (D) at (0,6) {};
\node [coordinate] (P) at (1,1) {};
\node [coordinate] (Q) at (5,1) {};
\node [coordinate] (R) at (3,5) {};
\fill<1-> [red] (A) -- (B) -- (Q) -- (P) -- cycle;
\fill<2-> [green] (B) -- (C) -- (R) -- (Q) -- cycle;
\fill<3-> [blue] (C) -- (D) -- (R) -- cycle;
\fill<4-> [yellow] (D) -- (A) -- (P) -- (R) -- cycle;
\end{tikzpicture}
\end{frame}
结果: