Consider the following MWE:
\documentclass[border=5pt,tikz]{standalone}
\usetikzlibrary{calc}
\tikzset{
car/.style={
scale=.5,minimum width=.1cm,minimum height=.5cm,fill=#1
}
}
\begin{document}
\foreach \n in {0,10,...,360,350,340,...,0}
{
\begin{tikzpicture}
\fill[green!60!black] ([xshift=1mm,yshift=-1mm]1,0) rectangle ([xshift=-1mm,yshift=1mm]4,-3);
\path ([xshift=1mm,yshift=-1mm]1,0) -- ([xshift=-1mm,yshift=1mm]4,-3) node[midway,fill=green!40!black,circle,inner sep=.3cm] (a) {};
\node[fill=green!40!black,circle,inner sep=.1cm,above left=.5cm] at (a) {};
\node[fill=green!40!black,circle,inner sep=.1cm,above right=.5cm] at (a) {};
\node[fill=green!40!black,circle,inner sep=.1cm,below left=.5cm] at (a) {};
\node[fill=green!40!black,circle,inner sep=.1cm,below right=.5cm] at (a) {};
\draw[double distance=2mm,double=gray] (5,0) -- (0,0) arc(-90:-360:1) --+ (0,-5) arc(0:-270:1) --+ (5,0) arc(90:-180:1) --+ (0,5) arc(180:-90:1);
\draw[white,densely dashed] (5,0) -- (0,0) arc(-90:-360:1) --+ (0,-5) arc(0:-270:1) --+ (5,0) arc(90:-180:1) --+ (0,5) arc(180:-90:1);
\node[shift={(0,1)},car=red,rotate=\n] at (\n:1) {};
\node[shift={(5,1)},car=blue,rotate=-\n] at (-\n:1) {};
\node[shift={(0,-4)},car=green,rotate=-\n] at (-\n:1) {};
\node[shift={(5,-4)},car=yellow,rotate=\n] at (\n:1) {};
\pgfmathsetmacro\factor{\n/360}
\node[rotate=-90,car=purple] at ($(0,0)!\factor!(5,0)$) {};
\node[rotate=-90,car=violet] at ($(5,-3)!\factor!(0,-3)$) {};
\node[car=brown] at ($(4,1)!\factor!(4,-4)$) {};
\node[car=orange] at ($(1,-3)!\factor!(1,0)$) {};
\end{tikzpicture}
}
\end{document}
Here is the output:
My questions is: How can I make the cars to move along those “arc-parts“ of the track? I would have work with \ifnum
, but I think it is too laborius …
decorations.matkings
?