我想要制作动画来表示彼得森图中长度为 5 的循环。我尝试了以下代码,但它只表示单个边。我想要制作包含所有边的动画。
\documentclass{article}
\usepackage{animate}
\usepackage{tikz}
\usepackage{tkz-graph}
\usetikzlibrary{arrows}
\usetikzlibrary{lindenmayersystems}
\usepackage[paperheight=11cm,paperwidth=11cm,bottom=0cm,top=0.21cm,left=0cm,right=0cm]{geometry}
\begin{document}
\begin{animateinline}[controls,autoplay,loop]{2}
\multiframe{12}{n=18+72}{
\begin{tikzpicture}
\foreach \x in {18,90,...,306}
{
\draw(\x:5cm) circle (5pt)[fill=black];
\draw(\x:3cm) circle (5pt)[fill=black];
\draw(\x:5cm) [line width=3pt]-- (\x+72:5cm);
\draw(\x:3cm) [line width=3pt] -- (\x+144:3cm);
\draw(\x:5cm) [line width=3pt] -- (\x:3cm);
}
\draw(\n:5cm)[line width=7pt,color=blue]--(\n+72:5cm); \end{tikzpicture}
}
\end{animateinline}
\end{document}
答案1
以下连续给外边缘着色:
\documentclass[border=10pt]{standalone}
%\documentclass{article}
\usepackage{animate}
\usepackage{tikz}
%\usepackage{tkz-graph}
%\usetikzlibrary{arrows}
%\usetikzlibrary{lindenmayersystems}
%\usepackage[paperheight=11cm,paperwidth=11cm,bottom=0cm,top=0.21cm,left=0cm,right=0cm]{geometry}
\begin{document}
\begin{animateinline}[controls,autoplay,loop]{2}
\multiframe{6}{i=0+1,n=-54+72}{
\begin{tikzpicture}
\foreach \x in {18,90,...,306}
{
\draw(\x:5cm) circle (5pt)[fill=black];
\draw(\x:3cm) circle (5pt)[fill=black];
\draw(\x:5cm) [line width=3pt]-- (\x+72:5cm);
\draw(\x:3cm) [line width=3pt] -- (\x+144:3cm);
\draw(\x:5cm) [line width=3pt] -- (\x:3cm);
}
\ifnum\i>0
\ifnum\i=1
\xdef\cycle{\n}
\else
\xdef\cycle{\cycle,\n}
\fi
\foreach \x in \cycle
{
\draw(\x:5cm)[line width=7pt,color=blue]--(\x+72:5cm);
}
\fi
\end{tikzpicture}
}
\end{animateinline}
\end{document}
答案2
这就是你想要的东西吗?
\documentclass{beamer}
\usepackage{tikz}
\tikzset{
invisible/.style={opacity=0},
visible on/.style={alt={#1{}{invisible}}},
alt/.code args={<#1>#2#3}{%
\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
},
}
\begin{document}
\begin{frame}[fragile]
\frametitle{Animation}
\begin{tikzpicture}[%
mydot/.style={circle, fill=#1, inner sep=0pt, outer sep=0pt, minimum width=10pt},
line width=3pt]
\foreach \x [evaluate=\x as \i using int(\x)] in {18,90,...,306}
{
\node[mydot=blue, visible on=<1->] (out-\i) at (\x:4cm) {};
\node[mydot=red, visible on=<2->] (in-\i) at (\x:2cm) {};
}
\foreach \i [evaluate=\i as \k using {int(mod(\i+72,360))},
evaluate=\i as \j using {int(mod(\i+144,360))}]
in {18,90,...,306}{
\draw[visible on=<4->] (out-\i) -- (in-\i);
\draw[visible on=<3->] (out-\i)--(out-\k);
\draw[visible on=<5->] (in-\i)--(in-\j);
}
\end{tikzpicture}
\end{frame}
\end{document}