# Creating Three Circle Traffic Light System

I'm trying to create a three tiered system with overlapping circles like the one below:

Such that each state should be immediately apparent at a glance (even to someone who's colour blind). I've found similar solutions like this one, but unfortunately my tikz knowledge is lacking on how to translate this into the above. Would anyone be able to show me how to do this?

• you can try with tikz matrix @Toby Hawkins Jul 30, 2017 at 2:52

Macros can be defined for each color. How the circles overlap depends on the order they are drawn, the second one is drawn over the first. With every path/.style={thick,fill=lightgray} the default style for the circles is set (line width and fill color here). The fill color is later overwritten with e.g. [fill=red] for individual circles. Using polar coordinates ((60:0.1), i.e. move 0.1 units away in a direction of 60°) makes it easier to place them in an equilateral triangle.

The macros also have an optional parameter, which makes it possible to scale the pictures.

\documentclass{article}
\usepackage{tikz}

\newcommand*{\TlRed}[1][1]{%
\begin{tikzpicture}[every path/.style={thick,fill=lightgray},scale=#1]
\draw (60:0.1) circle (0.07);
\draw (0.1,0)  circle (0.07);
\draw[fill=red] (0,0) circle (0.07);
\end{tikzpicture}%
}
\newcommand*{\TlYellow}[1][1]{%
\begin{tikzpicture}[every path/.style={thick,fill=lightgray},scale=#1]
\draw (0,0)    circle (0.07);
\draw (60:0.1) circle (0.07);
\draw[fill=yellow] (0.1,0) circle (0.07);
\end{tikzpicture}%
}
\newcommand*{\TlGreen}[1][1]{%
\begin{tikzpicture}[every path/.style={thick,fill=lightgray},scale=#1]
\draw (0,0)    circle (0.07);
\draw (0.1,0)  circle (0.07);
\draw[fill=green] (60:0.1) circle (0.07);
\end{tikzpicture}%
}

\begin{document}
M \TlRed \TlYellow \TlGreen\ M

\vspace{1ex}
{\Large M \TlRed[1.5] \TlYellow[1.5] \TlGreen[1.5] M}

\vspace{1ex}
\begin{tabular}{|l|c|c|c|}\hline
& bad & hm... & good \\\hline
Traffic light & \TlRed & \TlYellow & \TlGreen \\\hline
\end{tabular}

\end{document}


• That's perfect! Thanks a lot Mike (also for your clear explanation)! Jul 30, 2017 at 4:11
• +1 nice work :) it seems that you might be able to reduce your code by defining one command, say \trafficLight that takes, as one of its arguments, a colour, so that you could simply say \trafficLight[red], etc Jul 30, 2017 at 6:59
• @cmhughes: not really, 1) the circles must be drawn in order to get the overlap right, 2) for red and yellow they are dran clockwise and for green counterclockwise, 3) there would have been no option to scale the traffic lights or the resulting code would be much more complicated, and therefore hard to understand for a beginner. And I have to admit, that I'm not yet that familiar with pgfkeys to get this done in an hour or so.
– Mike
Jul 30, 2017 at 13:51