I want to draw a path where edges have alternating colors, like:
Ideally I want to use
\draw[red] (3,0)-- (3.5,0.5) -- (4,0.2) -- (4,-0.2) -- (3.5,-0.5) -- cycle;
But this can only specify a single color for the entire path. The best I can do is to use \path below then I need to repeat every coordinate twice, which is very awkward. I was wondering
(a) if this can accomplished in the style \draw + cycle as above by specifying the color of each edge along the way.
(b) if somehow the operation of alternating color can be automated, that would be even better!
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\path
(3,0) edge[blue] (3.5,0.5)
(3.5,0.5) edge[red] (4,0.2)
(4,0.2) edge[blue] (4,-0.2)
(4,-0.2) edge[red] (3.5,-0.5)
(3.5,-0.5) edge[blue] (3,0);
\end{tikzpicture}
\end{document}

\documentclass[tikz,margin=3mm]{standalone} \begin{document} \begin{tikzpicture}[every edge/.append style = {draw=blue, line cap=round}] \path (3,0) edge (3.5,0.5) (3.5,0.5) edge[red] (4,0.2) (4,0.2) edge (4,-0.2) (4,-0.2) edge[red] (3.5,-0.5) (3.5,-0.5) edge (3,0); \end{tikzpicture} \end{document}gives what you looking for? – Zarko Oct 13 '17 at 20:54