如何在 Tikz/PGF 中在特定时间逐个显示(或动画)三个图形?

如何在 Tikz/PGF 中在特定时间逐个显示(或动画)三个图形?

这个帖子之后,我学会了绘制数学中以下三个有趣的图形(p-adic numers):

\begin{tikzpicture}
        \draw[ ] (0,0) circle [radius=3];
        \node at (0,2) {0};
        \node at (2,-1) {1};
        \node at (-2,-1) {2};
        \end{tikzpicture}
\newcommand{\RA}{1.5}
        \pgfmathsetmacro{\RB}{\RA*(1+2/sqrt(3)}
        \begin{tikzpicture}
        \draw[ ] (0,0) circle[radius=\RB cm];
        \foreach \ang in {90,210,330}
        \draw[ ] (\ang:\RB-\RA) circle[radius=\RA cm];
        \node[red] at (0,2.5) {0};
        \node[red] at (-0.8,1.5) {6};
        \node[red] at (0.8,1.5) {3};
        \node[red] at (1.7,-0.1) {1};
        \node[red] at (2.4,-1.3) {4};
        \node[blue] at (1,-1.3) {7};
        \node[red] (8) at (-2.4,-1.3) {8};
        \node[blue] at (-1,-1.3) {5};
        \node[red] at (-1.7,-0.1) {2};
        \end{tikzpicture}
\newcommand{\RRA}{4}
            \pgfmathsetmacro{\RRB}{\RRA/(1+2/sqrt(3)}
            \begin{tikzpicture}
            \draw[ ] (0,0) circle[radius=\RRA cm];
            \foreach \ang [count = \i from 1] in {90,210,330}
            \draw[ ] (\ang:\RRA-\RRB) coordinate (center-\i) circle[radius=\RRB cm];
            \pgfmathsetmacro{\RRC}{\RRB/(1+2/sqrt(3)}
            \foreach \i in {1,2,3}
            \foreach \ang in {90,210,330}
            \draw[ ] ($(center-\i)+(\ang:\RRB-\RRC)$) circle[radius=\RRC cm];
            \node[red] at (0,3.6) {0};
            \node[red] at (0.3,3) {18};
            \node[green] at (-0.3,3) {9};
            \node[red] at (0.9,2.1) {6};
            \node[red] at (1.2,1.4) {24};
            \node[green] at (0.5,1.4) {15};
            \node[cyan] at (-0.5,1.4) {21};
            \node[cyan] at (-0.9,2.1) {3};
            \node at (-1.2,1.4) {12};
            \node[red] at (1.8,0.5) {2};
            \node[purple] at (-1.8,0.5) {1};
            \node at (-2.2,-0.33) {10};
            \node[purple] at (-1.4,-0.33) {19};
            \node[red] at (2.2,-0.33) {20};
            \node[green] at (1.4,-0.33) {11};
            \node[red] at (2.7,-1) {8};
            \node[red] at (3.2,-1.8) {26};
            \node[green] at (2.3,-1.8) {17};
            \node[cyan] (7) at (1,-1.1) {5};
            \node[cyan] (7) at (1.5,-1.8) {23};
            \node (7) at (0.5,-1.8) {14};
            \node[red] at (-2.7,-1) {4};
            \node at (-3.2,-1.8) {13};
            \node[red] at (-2.3,-1.8) {22};
            \node[purple] (7) at (-1,-1.1) {7};
            \node (7) at (-1.5,-1.8) {16};
            \node[purple] (7) at (-0.5,-1.8) {25};
            \end{tikzpicture}

上述三段 Tikz 代码分别给出以下三幅图:

在此处输入图片描述

在此处输入图片描述

在此处输入图片描述

我的问题:

我想以这样的方式为这三个图形制作动画,即第一个图形显示 5 秒,然后第二个图形显示 5 秒,然后第三个图形也显示 5 秒。

我有PGF/TikZ 手册但无法在这里申请。

感谢您的帮助。

编辑:

我的序言如下:

\documentclass[12pt,reqno]{amsart}
\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{compat=newest}
\pgfplotsset{ytick style={draw=none}}
\pgfplotsset{xtick style={draw=none}}
\topmargin=0.02cm
\textwidth =  17cm
\textheight = 23cm
\baselineskip=11pt
\setcounter{secnumdepth}{3}
\setlength{\oddsidemargin}{0.01 pt}
\setlength{\evensidemargin}{0.01 pt}
\renewcommand{\baselinestretch}{1.4}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage{graphicx}
\graphicspath{ }
%\usepackage[bookmarks=false]{hyperref}
%\usetikzlibrary{animations}
\usepackage{mathrsfs}
\usepackage{epstopdf}
\usepackage{csquotes}
\usepackage{wrapfig}
\usepackage{accents}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{calligra}
\usepackage[colorlinks]{hyperref}
\usepackage{kantlipsum}
\hypersetup{colorlinks, 
    breaklinks,
    linkcolor=red,
    citecolor=red,
    linktocpage=true}
\newtheorem{fig}{figure}[section]
\numberwithin{figure}{section}
\newcommand\norm[1]{\left\lVert#1\right\rVert}
\theoremstyle{plain}
\newtheorem{thm}{Theorem}[section]
\newtheorem{lem}[thm]{Lemma}
\newtheorem{prop}[thm]{Proposition}
\newtheorem{cor}{Corollary}[thm]
\theoremstyle{definition}
\newtheorem{defn}{Definition}[section]
\newtheorem{conj}{Conjecture}[section]
\newtheorem{exmp}{Example}[section]
\setcounter{tocdepth}{3}
\theoremstyle{remark}
\newtheorem*{rem}{Remark}
\newtheorem*{note}{Note}
\usetikzlibrary{calc}
\usepackage{mathtools}
\makeatletter
\@namedef{subjclassname@2020}{%
    \textup{2020} Mathematics Subject Classification}

\makeatother

\begin{document}
....
\end{document}

答案1

由于 OP 中的代码不完整/可编译,下面提供一个简单的示例来演示如何设置每帧显示 5 秒的动画:

\documentclass{article}
\usepackage{animate}

\begin{document}
\begin{animateinline}[autoplay]{0.2}% 0.2 FPS corresponds to 5 s of frame visibility
  \fbox{1}
\newframe
  \fbox{2}
\newframe
  \fbox{3}
\newframe % <-- this makes the last one disappear after another 5 s, as requested
\end{animateinline}
\end{document}

可以通过可选\newframe参数为每个帧或动画部分单独设置帧速率:

\documentclass{article}
\usepackage{animate}

\begin{document}
\begin{animateinline}[autoplay]{0.2}% 0.2 FPS corresponds to 5 s of frame visibility
  \fbox{1}
\newframe[0.5] % the next frame is shown for 2 s
  \fbox{2}
\newframe[0.2] % reset to 5 s visibility
  \fbox{3}
\newframe % <-- this makes the last one disappear after another 5 s, as requested
\end{animateinline}
\end{document}

Okular 和 A-Reader 可用于观看动画。

答案2

这使用texpower包。它与 beamer 一样复杂,但在应用上完全不同。

\documentclass[12pt,reqno]{amsart}
\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{compat=newest}
\pgfplotsset{ytick style={draw=none}}
\pgfplotsset{xtick style={draw=none}}
\topmargin=0.02cm
\textwidth =  17cm
\textheight = 23cm
\baselineskip=11pt
\setcounter{secnumdepth}{3}
\setlength{\oddsidemargin}{0.01 pt}
\setlength{\evensidemargin}{0.01 pt}
\renewcommand{\baselinestretch}{1.4}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage{graphicx}
\graphicspath{ }
%\usepackage[bookmarks=false]{hyperref}
%\usetikzlibrary{animations}
\usepackage{mathrsfs}
\usepackage{epstopdf}
\usepackage{csquotes}
\usepackage{wrapfig}
\usepackage{accents}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{calligra}
\usepackage[colorlinks]{hyperref}
\usepackage{kantlipsum}
\hypersetup{colorlinks, 
    breaklinks,
    linkcolor=red,
    citecolor=red,
    linktocpage=true}
\newtheorem{fig}{figure}[section]
\numberwithin{figure}{section}
\newcommand\norm[1]{\left\lVert#1\right\rVert}
\theoremstyle{plain}
\newtheorem{thm}{Theorem}[section]
\newtheorem{lem}[thm]{Lemma}
\newtheorem{prop}[thm]{Proposition}
\newtheorem{cor}{Corollary}[thm]
\theoremstyle{definition}
\newtheorem{defn}{Definition}[section]
\newtheorem{conj}{Conjecture}[section]
\newtheorem{exmp}{Example}[section]
\setcounter{tocdepth}{3}
\theoremstyle{remark}
\newtheorem*{rem}{Remark}
\newtheorem*{note}{Note}
\usetikzlibrary{calc}
\usepackage{mathtools}

\makeatletter
\@namedef{subjclassname@2020}{%
    \textup{2020} Mathematics Subject Classification}
\makeatother

\usepackage[display]{texpower}

\begin{document}
Some text.

\stepwise{%
\steponce{\begin{tikzpicture}
        \draw[ ] (0,0) circle [radius=3];
        \node at (0,2) {0};
        \node at (2,-1) {1};
        \node at (-2,-1) {2};
        \end{tikzpicture}}
        
\steponce{\newcommand{\RA}{1.5}%
        \pgfmathsetmacro{\RB}{\RA*(1+2/sqrt(3)}%
        \begin{tikzpicture}
        \draw[ ] (0,0) circle[radius=\RB cm];
        \foreach \ang in {90,210,330}
        \draw[ ] (\ang:\RB-\RA) circle[radius=\RA cm];
        \node[red] at (0,2.5) {0};
        \node[red] at (-0.8,1.5) {6};
        \node[red] at (0.8,1.5) {3};
        \node[red] at (1.7,-0.1) {1};
        \node[red] at (2.4,-1.3) {4};
        \node[blue] at (1,-1.3) {7};
        \node[red] (8) at (-2.4,-1.3) {8};
        \node[blue] at (-1,-1.3) {5};
        \node[red] at (-1.7,-0.1) {2};
        \end{tikzpicture}}
        
\steponce{\newcommand{\RRA}{4}%
            \pgfmathsetmacro{\RRB}{\RRA/(1+2/sqrt(3)}%
            \begin{tikzpicture}
            \draw[ ] (0,0) circle[radius=\RRA cm];
            \foreach \ang [count = \i from 1] in {90,210,330}
            \draw[ ] (\ang:\RRA-\RRB) coordinate (center-\i) circle[radius=\RRB cm];
            \pgfmathsetmacro{\RRC}{\RRB/(1+2/sqrt(3)}
            \foreach \i in {1,2,3}
            \foreach \ang in {90,210,330}
            \draw[ ] ($(center-\i)+(\ang:\RRB-\RRC)$) circle[radius=\RRC cm];
            \node[red] at (0,3.6) {0};
            \node[red] at (0.3,3) {18};
            \node[green] at (-0.3,3) {9};
            \node[red] at (0.9,2.1) {6};
            \node[red] at (1.2,1.4) {24};
            \node[green] at (0.5,1.4) {15};
            \node[cyan] at (-0.5,1.4) {21};
            \node[cyan] at (-0.9,2.1) {3};
            \node at (-1.2,1.4) {12};
            \node[red] at (1.8,0.5) {2};
            \node[purple] at (-1.8,0.5) {1};
            \node at (-2.2,-0.33) {10};
            \node[purple] at (-1.4,-0.33) {19};
            \node[red] at (2.2,-0.33) {20};
            \node[green] at (1.4,-0.33) {11};
            \node[red] at (2.7,-1) {8};
            \node[red] at (3.2,-1.8) {26};
            \node[green] at (2.3,-1.8) {17};
            \node[cyan] (7) at (1,-1.1) {5};
            \node[cyan] (7) at (1.5,-1.8) {23};
            \node (7) at (0.5,-1.8) {14};
            \node[red] at (-2.7,-1) {4};
            \node at (-3.2,-1.8) {13};
            \node[red] at (-2.3,-1.8) {22};
            \node[purple] (7) at (-1,-1.1) {7};
            \node (7) at (-1.5,-1.8) {16};
            \node[purple] (7) at (-0.5,-1.8) {25};
            \end{tikzpicture}}}
            
Some more text
\end{document}

相关内容