我正在使用 beamer
我在图像上绘制一些图形,这些图形应该按顺序出现在图像上。
\documentclass{beamer}
\usepackage{tikz}
\begin{document}
\begin{frame}
\begin{tikzpicture}
\node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[width=0.9\textwidth]{1.png}};
\begin{scope}[x={(image.south east)},y={(image.north west)}]
\draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
\foreach \x in {0,1,...,9} { \node [anchor=north] at (\x/10,0) {0.\x}; }
\foreach \y in {0,1,...,9} { \node [anchor=east] at (0,\y/10) {0.\y}; }
\draw[red,ultra thick,rounded corners] (0.2,0.84) rectangle (0.1,0.95); \pause
\draw[red,ultra thick,rounded corners] (0.52,0.7) rectangle (0.85,0.36); \pause
\draw[red,ultra thick,rounded corners] (0.09,0.84) rectangle (0.294,0.16); \pause
\draw[red,ultra thick,rounded corners] (0.12,0.15) rectangle (0.294,0.06); \pause
\draw[red,ultra thick,rounded corners] (0.36,0.7) rectangle (0.48,0.31); \pause
\draw[red,ultra thick,rounded corners] (0.04,0.94) rectangle (0.85,0.2);
\end{scope}
\end{tikzpicture}
\end{frame}
\end{document}
问题:图像上出现新图形后,我希望旧图形淡出。
这该怎么做?非常感谢您的帮助。
答案1
如果您想要动画淡入淡出,beamer
可以通过创建多个幻灯片来实现,这些幻灯片上的对象颜色略有不同,并快速连续显示这些对象(就像翻书一样,仅在演示模式下有效)。这可能会生成包含许多页面的 pdf,我不确定您是否想要。此外,淡入不可见可能会有问题。当前版本的 beamer(3.36)不支持“真正的”透明度,因此通过将对象的颜色与框架背景颜色混合来伪造它。这会在您的情况下导致问题,因为您正在图形上绘制形状。在尝试使对象透明时,beamer
实际上会使它们变为白色(以匹配背景),而不管图形颜色如何。
如果您希望对象在绘制之后完全消失,则可以使用\visible
指定每个对象应在哪些幻灯片上可见。
\documentclass{beamer}
\usepackage{tikz}
\begin{document}
\begin{frame}
\begin{tikzpicture}
\node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[width=0.9\textwidth]{example-image}};
\begin{scope}[x={(image.south east)},y={(image.north west)}]
\draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
\foreach \x in {0,1,...,9} { \node [anchor=north] at (\x/10,0) {0.\x}; }
\foreach \y in {0,1,...,9} { \node [anchor=east] at (0,\y/10) {0.\y}; }
\visible<1>{\draw[red,ultra thick,rounded corners] (0.2,0.84) rectangle (0.1,0.95);}
\visible<2>{\draw[red,ultra thick,rounded corners] (0.52,0.7) rectangle (0.85,0.36);}
\visible<3>{\draw[red,ultra thick,rounded corners] (0.09,0.84) rectangle (0.294,0.16);}
\visible<4>{\draw[red,ultra thick,rounded corners] (0.12,0.15) rectangle (0.294,0.06);}
\visible<5>{\draw[red,ultra thick,rounded corners] (0.36,0.7) rectangle (0.48,0.31);}
\visible<6>{\draw[red,ultra thick,rounded corners] (0.04,0.94) rectangle (0.85,0.2);}
\end{scope}
\end{tikzpicture}
\end{frame}
\end{document}
或者,您可以使用\temporal
来定义给定幻灯片之前、之上和之后的外观。在下文中,\colorize
定义为在给定幻灯片之前不可见,在给定幻灯片上为红色,此后为 35% 黑色。
\documentclass{beamer}
\usepackage{tikz}
\def\colorize<#1>{%
\temporal<#1>{\invisible<-#1>}{\color{red}}{\color{black!35}}}
\begin{document}
\begin{frame}
\begin{tikzpicture}
\node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[width=0.9\textwidth]{example-image}};
\begin{scope}[x={(image.south east)},y={(image.north west)}]
\draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
\foreach \x in {0,1,...,9} { \node [anchor=north] at (\x/10,0) {0.\x}; }
\foreach \y in {0,1,...,9} { \node [anchor=east] at (0,\y/10) {0.\y}; }
\colorize<1>{\draw[ultra thick,rounded corners] (0.2,0.84) rectangle (0.1,0.95);}
\colorize<2>{\draw[ultra thick,rounded corners] (0.52,0.7) rectangle (0.85,0.36);}
\colorize<3>{\draw[ultra thick,rounded corners] (0.09,0.84) rectangle (0.294,0.16);}
\colorize<4>{\draw[ultra thick,rounded corners] (0.12,0.15) rectangle (0.294,0.06);}
\colorize<5>{\draw[ultra thick,rounded corners] (0.36,0.7) rectangle (0.48,0.31);}
\colorize<6>{\draw[ultra thick,rounded corners] (0.04,0.94) rectangle (0.85,0.2);}
\end{scope}
\end{tikzpicture}
\end{frame}
\end{document}