我是巴西人,18 岁,大学上半年我有一个期末项目。我在这里找到了一个模拟时钟的代码,并做了修改以创建速度计。我想知道如何使用自动播放来制作动画。
\documentclass[tikz,border=0pt,dvipsnames]{standalone}
\usepackage{animate}
\usepackage{tikz}
\begin{document}
\foreach \hdeg / \mdeg in {0/0,2/30,4/60,6/90,8/120,10/150,12/180,14/210,
16/240}{ % pontos do mínimo ao máximo de rotação
\begin{tikzpicture}[line cap=round,line width=3pt]
\filldraw [fill=white!30] (0,0) circle (2cm); % cor e tamanho do círculo
\foreach \angle / \label in
{0/140, 30/120, 60/100, 90/80, 120/60, 150/40, 180/20,
210/0, 330/160} % Kilômetros
{
\draw[line width=2pt] (\angle:1.7cm) -- (\angle:2cm); % grossura e ângulo dos tracinhos dos KM's
\draw (\angle:1.4cm) node{\textsf{\label}};
}
\foreach \angle / \label in
{15/, 45/, 75/, 105/, 135/, 165/, 195/,345/, 270/SENAC-SP} % traços dos KM's sem número
{
\draw[line width=1pt] (\angle:1.8cm) -- (\angle:2cm);
\draw (\angle:1.4cm) node{\textsf{\label}};
}
\foreach \angle in {0,90,180,270}
\draw[line width=2pt] (\angle:2cm) -- (\angle:2cm);
\node[draw=none,font=\tiny,text=red] at (0,0.3cm) {Velocimetro PI - 1}; %texto
\draw[rotate=210,line width=1.5pt] (0,0) -- (-\mdeg:1cm); % ponteiro
\path [fill=red] (0,0) circle (3pt); % borda do círculo do ponteiro
\path [fill=white] (0,0) circle (2pt); % círculo do ponteiro
\end{tikzpicture}
}
\end{document}
答案1
这是一个可能的解决方案,其中animationinline
从包中使用animate
。请复制并粘贴,然后编译以查看动画。基本上,人们将包装在如下所示的环境tikzpicture
中。这里表示显示推底,但不会有推底。{10} 表示每节帧数。是一个整数变量;例如,对于实数变量,人们使用。0+1 表示从 0、1、2 开始计数,而 1+1 表示从 1、2、3 开始计数。 animationinline
controls
autoplay
imedeg
rxxx
\begin{animateinline}[poster=first,controls]{10}
\multiframe{9}{imdeg=0+1}
{
tikzpicture environment where \imdeg is the counter
}
\end{animationinline}
附录:讨论了第二种方法。
\multido{\imdeg=0+1}{9}
{
\begin{preview}
tikzpicture environment where \imdeg is the counter
\end{preview}
}
代码
\documentclass[border=10pt]{standalone}
\usepackage{animate}
\usepackage{tikz}
\begin{document}
\begin{animateinline}[poster=first,controls]{10}
\multiframe{9}{imdeg=0+1}
%\foreach \hdeg / \mdeg in {0/0,2/30,4/60,6/90,8/120,10/150,12/180,14/210,16/240}
{ % pontos do mínimo ao máximo de rotação
\begin{tikzpicture}[line cap=round,line width=3pt]
\filldraw [fill=white!30] (0,0) circle (2cm); % cor e tamanho do círculo
\foreach \angle / \label in
{0/140, 30/120, 60/100, 90/80, 120/60, 150/40, 180/20,
210/0, 330/160} % Kilômetros
{
\draw[line width=2pt] (\angle:1.7cm) -- (\angle:2cm); % grossura e ângulo dos tracinhos dos KM's
\draw (\angle:1.4cm) node{\textsf{\label}};
}
\foreach \angle / \label in
{15/, 45/, 75/, 105/, 135/, 165/, 195/,345/, 270/SENAC-SP} % traços dos KM's sem número
{\draw[line width=1pt] (\angle:1.8cm) -- (\angle:2cm);
\draw (\angle:1.4cm) node{\textsf{\label}};
}
\foreach \angle in {0,90,180,270}
\draw[line width=2pt] (\angle:2cm) -- (\angle:2cm);
\node[draw=none,font=\tiny,text=red] at (0,0.3cm) {Velocimetro PI - 1}; %texto
\draw[rotate=210,line width=1.5pt] (0,0) -- (-\imdeg*30:1cm); % ponteiro%%%
\path [fill=red] (0,0) circle (3pt); % borda do círculo do ponteiro
\path [fill=white] (0,0) circle (2pt); % círculo do ponteiro
\end{tikzpicture}
}
\end{animateinline}
\end{document}
附录:第二种方法是使用multido
包preview
。
代码:
\documentclass{standalone}%[border=10pt]{standalone}
\usepackage{animate}
\usepackage{tikz}
\usepackage{multido}
\usepackage[active,tightpage]{preview}
\begin{document}
\multido{\imdeg=0+1}{9}
%\foreach \hdeg / \mdeg in {0/0,2/30,4/60,6/90,8/120,10/150,12/180,14/210,16/240}
{ % pontos do mínimo ao máximo de rotação
\begin{preview}
\begin{tikzpicture}[line cap=round,line width=3pt]
\filldraw [fill=white!30] (0,0) circle (2cm); % cor e tamanho do círculo
\foreach \angle / \label in
{0/140, 30/120, 60/100, 90/80, 120/60, 150/40, 180/20,
210/0, 330/160} % Kilômetros
{
\draw[line width=2pt] (\angle:1.7cm) -- (\angle:2cm); % grossura e ângulo dos tracinhos dos KM's
\draw (\angle:1.4cm) node{\textsf{\label}};
}
\foreach \angle / \label in
{15/, 45/, 75/, 105/, 135/, 165/, 195/,345/, 270/SENAC-SP} % traços dos KM's sem número
{\draw[line width=1pt] (\angle:1.8cm) -- (\angle:2cm);
\draw (\angle:1.4cm) node{\textsf{\label}};
}
\foreach \angle in {0,90,180,270}
\draw[line width=2pt] (\angle:2cm) -- (\angle:2cm);
\node[draw=none,font=\tiny,text=red] at (0,0.3cm) {Velocimetro PI - 1}; %texto
\draw[rotate=210,line width=1.5pt] (0,0) -- (-{\imdeg*30}:1cm); % ponteiro%%%
\path [fill=red] (0,0) circle (3pt); % borda do círculo do ponteiro
\path [fill=white] (0,0) circle (2pt); % círculo do ponteiro
\end{tikzpicture}
\end{preview}
}
\end{document}