# How to add coloured corners to zigzag line in TikZ?

Is there any easy way to draw in TikZ an edge decorated with zigzag style, in which every corner is coloured, so that the result will be similar to:

I thought about creating such line by hand - by calculating all corners coordinates and drawing nodes there - but that seems very problematic, as I want to draw many such lines in different directions, I would also like to manipulate their segment lengths and amplitudes. Zigzag decoration just seems perfect for that - apart from no obvious way to colour corners.

Is there any nice way to do so? I'm new to TikZ.

• You can add decorations in predefined intervals. Can you give us a compilable test file? Apr 22 at 22:08

## 1 Answer

You can add a marking decoration to a zigzag decoration.

The amplitude and segment length of the zigzag decoration will determine where the marks must be. The mark command can be used with distances or percentages, so mark=between positions .35355cm and 1 step .7071cm will place a mark starting at √2/4 cm and then every √2/2 cm, until position 1, which is the end of the path.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing, decorations.markings}

\tikzset{
dot/.style={fill=red, circle, inner sep=0pt, minimum size=2mm},
dotzz/.style={
decorate, decoration={zigzag, amplitude=.25cm, segment length=1cm},
postaction={decorate, decoration={markings,
mark=between positions .35355cm and 1 step .7071cm with{\node[dot]{};}}}
}
}

\begin{document}

\begin{tikzpicture}
\draw[dotzz](0,0)--(4,3);
\end{tikzpicture}

\end{document}


Kind of works with curves also:

\draw[dotzz](0,0) circle[radius=3cm];