animateinline 问题

animateinline 问题

我有几个关于乳胶动画的问题

1)动画运行时闪烁

2)动画显示为一个滑动窗口,我想保留已经播放的动画(因此整个动画在动画结束时可见)

3) 在动画中,播放的四条线上的偏转在特定时刻用特定颜色着色。我想用相应的颜色为偏转两侧的两个点着色。目前只有朝下的点被着色。

任何帮助和改进都是非常欢迎的:)

\documentclass{standalone}
\usepackage{lmodern}
\usepackage{ifthen}
\usepackage{tikz,animate}
\usetikzlibrary{decorations,positioning,shapes}
\usepackage{pdfpages}
\usetikzlibrary{calc}
\usepackage{adjustbox}
\usepackage{xsavebox}

 \newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}   
 %used for the item box around

\begin{document}
\newcommand\neuronX{2.5}%
\newcommand\neuronY{9.5}%

%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% static objects shared by all frames
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{xlrbox}{staticElems}%
\begin{tikzpicture}
\path[use as bounding box] (0,6) rectangle (14,11);

\draw[] (1.6,6.8) rectangle ++(0.1,3.5);
\draw[] (1.2,8.6) rectangle ++(0.1,1.7);
\draw[] (1.4,7.9) rectangle ++(0.1,2.4);
\draw[] (1,9.0) rectangle ++(0.1,1.3);

\node[] at (10.5,9.5) {Channel 1};
\node[] at (10.5,8.5) {Channel 2};
\node[] at (10.5,7.5) {Channel 3};
\node[] at (10.5,6.5) {Channel 4};

\node [circle,draw,fill = red] at (\neuronX,\neuronY) (N1) {};
\node [circle,draw,below right = 0.4cm and 0.4cm of N1,fill = green] () {};
\node [circle,draw,below right = 2.2cm and 0.2cm of N1,,fill = blue] () {};

% save bounding box coordinates
\coordinate (LowerLeft) at (current bounding box.south west);
\coordinate (UpperRight) at (current bounding box.north east);
\end{tikzpicture}%
\end{xlrbox}%
% the empty graph to start with
\begin{xlrbox}{mygraph}%
\begin{tikzpicture}
\path[use as bounding box] (LowerLeft) rectangle (UpperRight);
\end{tikzpicture}%
\end{xlrbox}%


%
% putting the animation together
\begin{animateinline}[autoplay]{8}%loop
\xusebox{staticElems} %first frame showing only the static objects
\newframe
\gdef\oldyOne{9.3}%
\gdef\oldyTwo{8.3}%
\gdef\oldyThree{7.3}%
\gdef\oldyFour{6.3}%
\multiframe{80}{rx=4.9+0.05}{%
    % set line colour, vertical graph displacement and which shaded
    % object to use
    %\def\whichShaded{shaded-2}%
    \def\linecolor{black}%
    \def\dy{9.3}%
    \def\dyTwo{8.3}%
    \def\dyThree{7.3}%
    \def\dyFour{6.3}%


    \def\nOne{0}
    \def\nTwo{0}
    \def\nThree{0}
    \def\nFour{0}

    \ifdim 5.3pt < \rx pt\relax%
    \ifdim  5.4pt > \rx pt\relax%
        \def\nOne{-0.4} 
        \def\linecolor{red}%    
    \fi%
    \fi%

    \ifdim 6.3pt < \rx pt\relax%
    \ifdim  6.4pt > \rx pt\relax%
        \def\nTwo{-0.4} 
            \def\linecolor{green}%

    \fi%
    \fi%

    \ifdim 6.8pt < \rx pt\relax%
    \ifdim  6.9pt > \rx pt\relax%
        \def\nThree{-0.4}   
        \def\linecolor{blue}%   
    \fi%
    \fi%

    \ifdim 7.1pt < \rx pt\relax%
    \ifdim  7.2pt > \rx pt\relax%
    \def\nOne{-0.4} 
    \def\linecolor{red}%    

    \fi%
    \fi%
    \ifdim 7.5pt < \rx pt\relax%
    \ifdim  7.6pt > \rx pt\relax%
    \def\nOne{-0.4} 
    \def\linecolor{red}%    
    \fi%
    \fi%

    % assemble the graph
    \pgfmathsetmacro{\oldx}{\rx-0.05}%
    \pgfmathsetmacro{\y}{0.1*rand}%
    \pgfmathsetmacro{\yTwo}{0.1*rand}%
    \pgfmathsetmacro{\yThree}{0.1*rand}%
    \pgfmathsetmacro{\yFour}{0.1*rand}%

    \pgfmathsetmacro{\chOne}{\dy+\nOne+\y}%
    \pgfmathsetmacro{\chTwo}{\dyTwo+\nOne + \nTwo+\yTwo}%
    \pgfmathsetmacro{\chThree}{\dyThree   + \nThree+ + \yThree}%
    \pgfmathsetmacro{\chFour}{\dyFour     + \nThree +  \yFour}%

    \begin{xlrbox}{mygraph}%
        %repeat previous graph
        \makebox[0pt][l]{\xusebox{mygraph}}%
        %
        %append new line segments
        \begin{tikzpicture}[line cap=round, draw=\linecolor]
        \path[use as bounding box,draw] (LowerLeft) rectangle (UpperRight);

        \draw (\oldx,\oldyOne) -- (\rx,\chOne);         

        \draw (\oldx,\oldyTwo) -- (\rx,\chTwo);

        \draw (\oldx,\oldyThree) -- (\rx,\chThree);

        \draw (\oldx,\oldyFour) -- (\rx,\chFour);


        \end{tikzpicture}%
    \end{xlrbox}%

    \xdef\oldyOne{\chOne}%
    \xdef\oldyTwo{\chTwo}%
    \xdef\oldyThree{\chThree}%
    \xdef\oldyFour{\chFour}%

    % overlay the static objects
    \makebox[0pt][l]{\xusebox{staticElems}}%
    %
    % put graph in the foreground
    %\xusebox{mygraph}%
    \xusebox{mygraph}%

}
\end{animateinline}

\end{document}

答案1

  1. 带有和不带有封闭矩形的边界框略有不同。这会导致在第一个带有静态元素的帧之后重新缩放帧。从 bbox 计算中排除矩形并将其放入静态帧(它实际上属于该帧)可解决闪烁问题:

    \path[use as bounding box] (0,6) rectangle (14,11);
    \draw [thick] (0,6) rectangle (14,11);
    

    此外,还有一些未受保护的行尾,它们堆积起来,在大矩形前面产生了虚假的空间。注释掉这些行尾可以删除这些空间。

  2. Acrobat Reader 中嵌套的 xsavebox 层数(PDF XObjects)似乎有上限。将函数线段放在同一层级并使用时间轴组装动画帧可解决线段消失的问题。

  3. 目前还不太清楚它应该是什么样子,但可能是这样的:

在此处输入图片描述

\documentclass{standalone}
\usepackage{lmodern}
\usepackage{ifthen}
\usepackage{tikz,animate}
\usetikzlibrary{decorations,positioning,shapes}
\usepackage{pdfpages}
\usetikzlibrary{calc}

%%%%%%%%%%%%%%%%%%%%%%%%
% writing timeline file
%%%%%%%%%%%%%%%%%%%%%%%%
\newwrite\TimeLineFile
\immediate\openout\TimeLineFile=neuron.txt
\foreach \i in {0,1,...,80} {
  % appending `x0' to transparency number --> keep all them all visible
  \immediate\write\TimeLineFile{::\i x0}
}
\immediate\closeout\TimeLineFile
%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
\newcommand\neuronX{2.5}%
\newcommand\neuronY{9.5}%

%staring points of curves
\def\dy{9.3}%
\def\dyTwo{8.3}%
\def\dyThree{7.3}%
\def\dyFour{6.3}%

\def\oldyOne{9.3}%
\def\oldyTwo{8.3}%
\def\oldyThree{7.3}%
\def\oldyFour{6.3}%

% putting the animation together
\begin{animateinline}[autoplay,timeline=neuron.txt]{8}%loop
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  % static objects shared by all frames
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \begin{tikzpicture}
  \path[use as bounding box] (0,6) rectangle (14,11);
  \draw [thick] (0,6) rectangle (14,11);

  \draw[] (1.6,6.8) rectangle ++(0.1,3.5);
  \draw[] (1.2,8.6) rectangle ++(0.1,1.7);
  \draw[] (1.4,7.9) rectangle ++(0.1,2.4);
  \draw[] (1,9.0) rectangle ++(0.1,1.3);

  \node[] at (10.5,9.5) {Channel 1};
  \node[] at (10.5,8.5) {Channel 2};
  \node[] at (10.5,7.5) {Channel 3};
  \node[] at (10.5,6.5) {Channel 4};

  \node [circle,draw,fill = red] at (\neuronX,\neuronY) (N1) {};
  \node [circle,draw,below right = 0.4cm and 0.4cm of N1,fill = green] () {};
  \node [circle,draw,below right = 2.2cm and 0.2cm of N1,,fill = blue] () {};

  % save bounding box coordinates
  \coordinate (LowerLeft) at (current bounding box.south west);
  \coordinate (UpperRight) at (current bounding box.north east);
  \end{tikzpicture}%
\newframe
\multiframe{80}{rx=4.9+0.05,dimx=4.9pt+0.05pt}{%
  %%%%%%%%%%%%%%%%
  % line segments
  %%%%%%%%%%%%%%%%
  % set line colour, vertical graph displacement and which shaded
  % object to use
  %\def\whichShaded{shaded-2}%
  \def\linecolor{black}%
%
  \def\nOne{0}%
  \def\nTwo{0}%
  \def\nThree{0}%
  \def\nFour{0}%
%
  \ifdim 5.3pt < \dimx\relax%
  \def\linecolor{red}%    
  \ifdim  5.4pt > \dimx\relax%
      \def\nOne{-0.4}%
  \fi%
  \fi%
%
  \ifdim 6.3pt < \dimx\relax%
  \def\linecolor{green}%
  \ifdim  6.4pt > \dimx\relax%
    \def\nTwo{-0.4}% 
  \fi%
  \fi%
%
  \ifdim 6.8pt < \dimx\relax%
  \def\linecolor{blue}%   
  \ifdim  6.9pt > \dimx\relax%
    \def\nThree{-0.4}%   
  \fi%
  \fi%
%
  \ifdim 7.1pt < \dimx\relax%
  \def\linecolor{red}%    
  \ifdim  7.2pt > \dimx\relax%
    \def\nOne{-0.4}% 
  \fi%
  \fi%
%  
  \ifdim 7.5pt < \dimx\relax%
  \def\linecolor{red}%    
  \ifdim  7.6pt > \dimx\relax%
    \def\nOne{-0.4}%
  \fi%
  \fi%
%
  % assemble the graph
  \pgfmathsetmacro{\oldx}{\rx-0.05}%
  \pgfmathsetmacro{\y}{0.1*rand}%
  \pgfmathsetmacro{\yTwo}{0.1*rand}%
  \pgfmathsetmacro{\yThree}{0.1*rand}%
  \pgfmathsetmacro{\yFour}{0.1*rand}%
%
  \pgfmathsetmacro{\chOne}{\dy+\nOne+\y}%
  \pgfmathsetmacro{\chTwo}{\dyTwo+\nOne + \nTwo+\yTwo}%
  \pgfmathsetmacro{\chThree}{\dyThree   + \nThree+ + \yThree}%
  \pgfmathsetmacro{\chFour}{\dyFour     + \nThree +  \yFour}%
%
  %new line segments
  \begin{tikzpicture}[line cap=round, draw=\linecolor]
    \path[use as bounding box] (LowerLeft) rectangle (UpperRight);

    \draw (\oldx,\oldyOne) -- (\rx,\chOne);         

    \draw (\oldx,\oldyTwo) -- (\rx,\chTwo);

    \draw (\oldx,\oldyThree) -- (\rx,\chThree);

    \draw (\oldx,\oldyFour) -- (\rx,\chFour);
  \end{tikzpicture}%
%
  \xdef\oldyOne{\chOne}%
  \xdef\oldyTwo{\chTwo}%
  \xdef\oldyThree{\chThree}%
  \xdef\oldyFour{\chFour}%
}
\end{animateinline}

\end{document}

相关内容