动画仅以特定间隔显示特定部分

动画仅以特定间隔显示特定部分

我有两个问题。

1)动画播放时闪烁,我无法理解,因为我在脚本中为每幅图画设置了一个边界框

2)一段时间后,动画将开始删除动画的第一个播放部分。(我想在播放结束后保留​​整个动画)

问候 Jesper

\documentclass{standalone}

\usepackage{graphicx}
\usepackage{lmodern}
\usepackage[utf8]{inputenc} 
\usepackage{tikz,animate}
\usetikzlibrary{decorations.pathmorphing,shapes.geometric}
\usetikzlibrary{positioning,shapes}

\usetikzlibrary{calc}
\usepackage{pdfpages}
\usepackage{adjustbox}
\usepackage{xsavebox}

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

\begin{document}

    \newcommand\neuronX{3}%
    \newcommand\neuronY{8.5}%

    %
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % static objects shared by all frames
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \begin{xlrbox}{staticElems}%
        \begin{tikzpicture}
        \path[use as bounding box,red] (0,5) rectangle (15,12);
        \draw [thick] (0,5) rectangle (15,12);

    \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 = 1cm and 0.8cm of N1,fill = green] () {};
    \node [circle,draw,below right = 2.2cm and 0.2cm of N1,,fill = blue] () {};
    \coordinate (A1) at (2.5,10);
    \coordinate (B1) at (2,6);
    \coordinate (A2) at (4 , 10);
    \coordinate (B2) at (4.5 , 6);

        % save bounding box coordinates
        \coordinate (LowerLeft) at (current bounding box.south west);
        \coordinate (UpperRight) at (current bounding box.north east);
        \end{tikzpicture}%
    \end{xlrbox}%
    %
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % two shaded objects
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \begin{xlrbox}{shaded-1}%
        \begin{tikzpicture}
        \path[use as bounding box,draw] (LowerLeft) rectangle (UpperRight);
        \shade[top color=orange,bottom color=orange,middle color = red,fill opacity=0.4] (A2) to [bend right=10] (B2) to [] (B1) to [bend right=10] (A1) to (A2);
        %\node[yshift = 10.5cm,xshift = 7.5cm] () {Light Pulse};
        \end{tikzpicture}%
    \end{xlrbox}%
    %
    \begin{xlrbox}{shaded-2}%
        \begin{tikzpicture}
        \path[use as bounding box,draw] (LowerLeft) rectangle (UpperRight);
        \shade[top color=white,bottom color=white,middle color = white] (A2) to [bend right=10] (B2) to [] (B1) to [bend right=10] (A1) to (A2);
        \end{tikzpicture}%
    \end{xlrbox}%
    %
    % the empty graph to start with
    \begin{xlrbox}{mygraph}%
        \begin{tikzpicture}
        \path[use as bounding box,draw] (LowerLeft) rectangle (UpperRight);
        \end{tikzpicture}%
    \end{xlrbox}%
    %
    % putting the animation together
    \begin{animateinline}[autoplay,loop]{8}
        \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\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}%


            %light          
            \ifdim 5.3pt < \rx pt\relax%
            \ifdim  5.6pt > \rx pt\relax%
            \def\whichShaded{shaded-1}%
            \fi%
            \fi%
            %neuron 1
            \ifdim 5.5pt < \rx pt\relax%
            \ifdim  5.6pt > \rx pt\relax%
            \def\nOne{-0.4} 
            \fi%
            \fi%    

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

            %neuron 1
            \ifdim 6.3pt < \rx pt\relax%
            \ifdim  6.6pt > \rx pt\relax%
                \def\whichShaded{shaded-1}%     
            \fi%
            \fi%


            \ifdim 6.5pt < \rx pt\relax%
            \ifdim  6.6pt > \rx pt\relax%
            \def\nOne{-0.4}      
            \fi%
            \fi%    

            \pgfmathsetmacro{\oldx}{\rx-0.05}%
            \pgfmathsetmacro{\y}{0.1*rand}%

            % 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]
                \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}%
            \end{xlrbox}%
            \xdef\oldyOne{\chOne}%
            \xdef\oldyTwo{\chTwo}%
            \xdef\oldyThree{\chThree}%
            \xdef\oldyFour{\chFour}%
            %
            % shaded object in the background
            \makebox[0pt][l]{\xusebox{\whichShaded}}%
            %
            % overlay the static objects
            \makebox[0pt][l]{\xusebox{staticElems}}%
            %
            % put graph in the foreground
            \xusebox{mygraph}%
        }
    \end{animateinline}


\end{document}

答案1

也许这正是你想要的?

\documentclass{standalone}
\usepackage{lmodern}
\usepackage{ifthen}
\usepackage{tikz,animate}
\usetikzlibrary{decorations,positioning,shapes,backgrounds}
\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}%

    %starting 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[] (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};


        % 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
            %%%%%%%%%%%%%%%%
            %
            \def\nOne{0}%
            \def\nTwo{0}%
            \def\nThree{0}%
            \def\nFour{0}%
            \def\lighto{4}% 
            \def\lightt{4}%
            %
            \def\linecolor{black}% 
            \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}% 
            \def\lighto{10}% 
            \def\lightt{10}%
            \fi%
            \fi%
            %
            \def\myopa{0}%
            \ifdim 6.3pt < \dimx\relax%
            \ifdim  6.6pt > \dimx\relax%
            \def\myopa{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);

            \node [circle,draw,fill = red] at (\neuronX,\neuronY) (N1) {};
            \node [circle,draw,below right =  1cm and 0.8cm of N1,fill = green] (N2) {};
            \node [circle,draw,below right = 2.2cm and 0.2cm of N1,,fill = blue] (N3) {};
            \begin{scope}[on background layer]
            \fill[red,fill opacity=\myopa,preaction={fill=white,fill opacity=1}] 
             ([xshift=-2mm,yshift=2mm]N1.north west) 
             -- ([xshift=2mm,yshift=2mm]N1.north east)
             -- ([xshift=2mm,yshift=2mm]N2.north east)
             -- ([xshift=2mm,yshift=-2mm]N2.south east)
             -- ([xshift=2mm,yshift=-2mm]N3.south east)
             -- ([xshift=-2mm,yshift=-2mm]N3.south west)
             -| cycle;           
            \end{scope}
            \end{tikzpicture}%
            %
            \xdef\oldyOne{\chOne}%
            \xdef\oldyTwo{\chTwo}%
            \xdef\oldyThree{\chThree}%
            \xdef\oldyFour{\chFour}%
        }
    \end{animateinline}

\end{document}

背景可见的时间间隔由以下因素决定:

            \def\myopa{0}%
            \ifdim 6.3pt < \dimx\relax%
            \ifdim  6.6pt > \dimx\relax%
            \def\myopa{0.4}%
            \fi%
            \fi%

还有很多其他方法可以做到这一点,但这里我使用backgrounds库来填充背面的内容。可以简化。

相关内容