考虑以下 MWE:
\documentclass[tikz]{standalone}
\begin{document}
\foreach \n in {0,1,2,...,72}{
\begin{tikzpicture}
\useasboundingbox (-2.5,-2.5) rectangle (2.5,2.5);
\pgfmathsetmacro{\q}{10*\n}
\draw[densely dotted] (0,-2.5) -- (0,2.5);
\draw (0,0) circle(1);
\draw (\q:1) -- (0,{2.5*sin(\q)});
\fill[black,radius=.1] (\q:1) circle;
\fill[red,radius=.1] (0,{2.5*sin(\q)}) circle; %use 1*sin(·) …
\end{tikzpicture}
}
\end{document}
我的问题是:如何在红点处进行追踪(以便一条线代表红点的路径)?
答案1
据我所知,您可以将其分为三种情况:
\documentclass[tikz]{standalone}
\begin{document}
\foreach \n in {0,1,2,...,27}{
\begin{tikzpicture}
\useasboundingbox (-2.5,-2.5) rectangle (2.5,2.5);
\pgfmathsetmacro{\q}{10*\n}
\draw[densely dotted] (0,-2.5) -- (0,2.5);
\draw (0,0) circle(1);
\draw (\q:1) -- (0,{2.5*sin(\q)});
\fill[black,radius=.1] (\q:1) circle;
\fill[red,radius=.1] (0,{2.5*sin(\q)}) circle; %use 1*sin(·) …
\draw[ultra thick,red] (0,0) -- (0,{2.5*sin(\q)});
\ifnum\n>9
\draw[ultra thick,red] (0,0) -- (0,2.5);
\fi
\ifnum\n>28
\draw[ultra thick,red] (0,-2.5) -- (0,2.5);
\fi
\end{tikzpicture}
}
\end{document}
答案2
这是真的只是为了好玩。没有竞争对手@samcarter 的回答很好其中大部分都是被盗的。
\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.footprints}
\begin{document}
\tikzset{cat prints/.style={decorate,decoration={footprints,foot length=2pt,stride
length=5pt,foot sep=1pt,foot of=felis silvestris},red}}
\foreach \n in {0,1,2,...,27}{
\begin{tikzpicture}
\useasboundingbox (-2.5,-2.5) rectangle (2.5,2.5);
\pgfmathsetmacro{\q}{10*\n}
\draw[densely dotted] (0,-2.5) -- (0,2.5);
\draw (0,0) circle(1);
\draw (\q:1) -- (0,{2.5*sin(\q)});
\fill[black,radius=.1] (\q:1) circle;
\fill[red,radius=.1] (0,{2.5*sin(\q)}) circle;
\ifnum\n<10
\draw[cat prints] (0,0) -- (0,{2.5*sin(\q)});
\else
\ifnum\n>9
\draw[cat prints] (0,0) -- (0,2.5);
\draw[cat prints] (0,2.5cm-0.5pt) -- (0,{2.5*sin(\q)});
\fi
\ifnum\n>28
\draw[cat prints] (0,0) -- (0,2.5);
\draw[cat prints] (0,2.5cm-0.5pt) -- (0,-2.5cm+0.5pt);
\draw[cat prints] (0,2.5) -- (0,{2.5*sin(\q)});
\fi
\fi
\end{tikzpicture}
}
\end{document}
更新:渐渐消失的足迹。还有鸭子女王。;-)
\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{decorations.footprints,ducks}
\newsavebox\Duck
\sbox\Duck{\tikz{\duck[crown,laughing, bill=red,longhair=black]}}
\newcounter{MyFootSteps}
\pgfdeclaremetadecoration{fading footprints}{initial}{ \state{initial}[width=0pt,
next state=footprint] {
\pgfmathparse{10-3*int(\pgfmetadecoratedpathlength/\pgfmetadecorationsegmentlength)}
\setcounter{MyFootSteps}{\pgfmathresult}
\pgfsetlinewidth{0.2pt}
\pgfset{/pgf/decoration/foot length=\pgfmetadecorationsegmentlength/5,/pgf/decoration/stride
length=\pgfmetadecorationsegmentlength/3,
/pgf/decoration/foot sep=1pt,/pgf/decoration/foot of=bird}
}
\state{footprint}[
switch if less than=\pgfmetadecorationsegmentlength to final,
width=\pgfmetadecorationsegmentlength/3, next state=footprint] {
\stepcounter{MyFootSteps}
\ifnum\theMyFootSteps>0
\pgfsetfillopacity{0.1*\theMyFootSteps}
\decoration{footprints}
\pgfusepathqfill
\fi
}
\state{final}{\pgfusepathqfill}
}
\begin{document}
\tikzset{fading cat prints/.style={decorate,decoration={fading footprints,meta-segment length=15pt}}}
\foreach \n in {0,1,2,...,35}{
\begin{tikzpicture}
\useasboundingbox (-2.5,-2.5) rectangle (2.5,2.5);
\pgfmathsetmacro{\q}{10*\n}
\draw[densely dotted] (0,-2.5) -- (0,2.5);
\draw (0,0) circle(1);
\draw (\q:1) -- (0,{2.5*sin(\q)});
\fill[black,radius=.1] (\q:1) circle;
\ifnum\n<10
\draw[fading cat prints] (0,-2.5) -- (0,{2.5*sin(\q)});
\else
\ifnum\n>9
\ifnum\n<29
\draw[fading cat prints] (0,0) -- (0,2.5) -- (0,{2.5*sin(\q)});
\else
\draw[fading cat prints] (0,0) -- (0,2.5) -- (0,-2.5) -- (0,{2.5*sin(\q)});
\fi
\fi
\fi
\node[scale=0.5] at (0,{2.5*sin(\q)}) {\usebox\Duck};
\end{tikzpicture}
}
\end{document}