![animate / TikZ:如何將 foreach-result 轉換為動畫 PDF](https://rvso.com/image/400383/animate%20%2F%20TikZ%EF%BC%9A%E5%A6%82%E4%BD%95%E5%B0%87%20foreach-result%20%E8%BD%89%E6%8F%9B%E7%82%BA%E5%8B%95%E7%95%AB%20PDF.png)
我從座標列表中繪製曲線並獲得 6 個獨立頁面。
有沒有簡單的方法可以使用 animate-package 將其作為 PDF 中的動畫圖片?
\documentclass[margin=5pt, tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{intersections}
\usepackage{amsmath, amssymb}
\begin{document}
\newcommand{\List}{}% reserve name
\let\List=\empty% create list
\def\Range{0,30,60,90,120,360}
\foreach \w in \Range{%%%%%%%%%%%%%%%
\pgfmathsetmacro\Winkel{\w} %
\begin{tikzpicture}[]
\coordinate[] (M) at (0,0);
\draw[] (M) circle[radius=3];
\draw[name path=kreis] (M) circle[radius=1.4];
\draw[name path=zeiger] (M) -- (90-\Winkel:3);
% Create List of Coordinates
\makeatletter
\path[name intersections={of=kreis and zeiger, name=S}] ;
\coordinate[label=left:$S_{\w}$] (S-\w) at (S-1);
\pgfmathsetmacro\temp{"(S-\w)"}%
\ifx\empty\List{} \xdef\List{\temp}%
\else \xdef\List{\List \temp}%
\fi
\makeatother
\draw[red] plot[mark=*] coordinates{\List};
\node[anchor=north west, text width=6 cm] at (-3,-3){List: \List};
\end{tikzpicture}
}%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}
答案1
根據 @AndéC 的提示,我得到了
% sub.tex
\documentclass[margin=5pt, tikz]{standalone}
\usepackage{animate}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{intersections}
\usepackage{amsmath, amssymb}
\begin{document}
\newcommand{\List}{}% reserve name
\let\List=\empty% create list
\def\Range{0,30,60,90,120,360}
\foreach \w in \Range{%%%%%%%%%%%%%%%
\pgfmathsetmacro\Winkel{\w} %
\begin{tikzpicture}[]
\useasboundingbox (-4,-4) rectangle (4,4);
\coordinate[] (M) at (0,0);
\draw[] (M) circle[radius=3];
\draw[name path=kreis] (M) circle[radius=1.4];
\draw[name path=zeiger] (M) -- (90-\Winkel:3);
% Create List of Coordinates
\makeatletter
\path[name intersections={of=kreis and zeiger, name=S}] ;
\coordinate[label=left:$S_{\w}$] (S-\w) at (S-1);
\pgfmathsetmacro\temp{"(S-\w)"}%
\ifx\empty\List{} \xdef\List{\temp}%
\else \xdef\List{\List \temp}%
\fi
\makeatother
\draw[red] plot[mark=*] coordinates{\List};
\node[anchor=north west, text width=6 cm] at (-3,-3){List: \List};
\end{tikzpicture}
}%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}
% arara: pdflatex
% arara: pdflatex
% main.tex
\documentclass[tikz]{standalone}
\usepackage{animate}
\begin{document}
\animategraphics[autoplay,loop,controls]{1}{sub}{}{}
\end{document}