TikZ 和 animateinline

TikZ 和 animateinline

我有 2 个演讲:

\documentclass{beamer}
\usepackage{tikz}
\usepackage{animate}
\begin{document}
\usetikzlibrary{calc,intersections}
  \begin{frame}
    \begin{center}
      \begin{tikzpicture}
         \useasboundingbox (3,0.5) rectangle (7,4.5);
         \pause
         \draw [name path=circle, line width=1](5,2.5) circle (2);
         \pause
         \draw [name path=line, line width=1](2,1)--(7,4) ;
         \path [name intersections={of = circle and line}];
         \coordinate (A) at (intersection-1);
         \coordinate (B) at (intersection-2);
         \pause
         \filldraw(A) circle (1.5pt);
         \pause    
         \filldraw(B) circle (1.5pt);
      \end{tikzpicture}
    \end{center}
  \end{frame}
\end{document} 

\documentclass{beamer}
\usepackage{tikz}
\usepackage{animate}
\begin{document}
\usetikzlibrary{calc}
   \begin{frame}
      \begin{animateinline}[autoplay]{90}
      \multiframe{121}{iAngle=0+3}
         {\begin{tikzpicture}
             \useasboundingbox (3,0.5) rectangle (7,4.5);
             \draw [line width=1](5,2.5) arc (0:\iAngle:2);
         \end{tikzpicture}}
      \end{animateinline}
   \end{frame}
\end{document} 

我想将它与所有功能结合起来。我这样做:

\documentclass{beamer}
\usepackage{tikz}
\usepackage{animate}
\begin{document}
   \usetikzlibrary{calc,intersections}
   \begin{frame}
      \begin{center}
         \begin{tikzpicture}
            \useasboundingbox (3,0.5) rectangle (7,4.5);
            \pause
                  \begin{animateinline}[autoplay]{90}
                     \multiframe{121}{iAngle=0+3}
                     {\draw [line width=1](5,2.5) arc (0:\iAngle:2);}
                  \end{animateinline}
            \draw [name path=circle, line width=1](5,2.5) circle (2);
            \pause
            \draw [name path=line, line width=1](2,1)--(7,4) ;
            \path [name intersections={of = circle and line}];
            \coordinate (A) at (intersection-1);
            \coordinate (B) at (intersection-2);
            \pause
            \filldraw(A) circle (1.5pt);
            \pause    
            \filldraw(B) circle (1.5pt);
         \end{tikzpicture}
      \end{center}
   \end{frame}
\end{document} 

我做错了什么?我该如何做对?

答案1

TikZ\draw本身不会产生具有非零宽度和高度的框,但animateinline需要某些非零大小的东西才能产生动画帧。

因此,tikzpicture环境必须围绕环境内的图形对象animateinline(如第二个代码框中的独立动画)。但您将其从“组合”文档(第三个代码框)中删除。因此,报告的错误

! Package animate Error: Contents of first frame must not have zero width...

动画应以普通格式保存lrbox,并作为 放在\node第二张幻灯片上(\node<2> ...)。 最终的动画帧应在具有动画的幻灯片之后的幻灯片上重复:

\documentclass{beamer}

\usepackage{tikz}
\usetikzlibrary{calc,intersections}

\usepackage{animate}

\newsavebox\myAnim

\begin{document}

  \begin{lrbox}{\myAnim}
    \begin{animateinline}[autoplay]{30}
    \multiframe{121}{iAngle=0+3}{
      \begin{tikzpicture}
        \useasboundingbox (3,0.5) rectangle (7,4.5);
        \draw [line width=1](5,2.5) arc (0:\iAngle:2);
      \end{tikzpicture}
    }
    \end{animateinline}
  \end{lrbox}

  \begin{frame}
     \begin{center}
        \begin{tikzpicture}
           \useasboundingbox (3,0.5) rectangle (7,4.5);
           \pause
           %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
           % animated object only on the second (<2>) slide
           %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
           \node<2> [inner sep=0, outer sep=0, anchor=south west] at (3,0.5) {\usebox\myAnim};
           \draw [name path=circle, line width=1](5,2.5) circle (2);
           %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
           \pause
           %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
           % repeat last animation frame on the slides to follow
           \begin{scope} %limit the clipping path on the `arc' object
             \clip (3,0.5) rectangle (7,4.5);
             \draw [line width=1](5,2.5) arc (0:360:2);
           \end{scope}
           %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
           \draw [name path=line, line width=1](2,1)--(7,4) ;
           \path [name intersections={of = circle and line}];
           \coordinate (A) at (intersection-1);
           \coordinate (B) at (intersection-2);
           \pause
           \filldraw(A) circle (1.5pt);
           \pause    
           \filldraw(B) circle (1.5pt);
        \end{tikzpicture}
     \end{center}
  \end{frame}
\end{document}

相关内容