4

I'm just going to admit that I'm useless at drawing images in LaTeX and revert to copy and paste and then adapting where possible. I had a look over at http://www.texample.net but couldn't find anything I could adapt. I want to create an image of a set of traffic lights with text to one side, like the image below. I want to use it as part of a score system where each colour means something. I probably looking for two items. The image below and then just the traffic lights where I could possibly put the score in the light it belongs.

enter image description here

PS: Sorry I have no MWE but don't know where to start with this. PPS: and sorry for putting up a help me draw this attached picture.

11
\documentclass[border=2mm, tikz]{standalone}

\usetikzlibrary{matrix, positioning}

\tikzset{
    trafficlight/.style = {%
        matrix of nodes,
        nodes in empty cells,
        rounded corners,
        draw = blue!70,
        fill = blue!30,
        nodes = {circle, minimum size=5mm, anchor=center, draw=black},
        row 1/.style={nodes={fill=red}},
        row 2/.style={nodes={fill=yellow}},
        row 3/.style={nodes={fill=green}},
        row sep=3mm,
    }
}

\begin{document}
\begin{tikzpicture}
\matrix[trafficlight] (A) { \\  \\ \\};
\node[right= 2mm of A-1-1] {Score 1};
\node[right= 2mm of A-2-1] {Score 2};
\node[right= 2mm of A-3-1] {Score 3};
\end{tikzpicture}
\end{document}

enter image description here

9
\documentclass{article}
\usepackage{stackengine,amssymb,xcolor}
\setstackgap{L}{16pt}
\savestack\trafficlight{%
  \stackinset{c}{.1pt}{c}{-1pt}{%
    \Longstack{\textcolor{red}{\Huge$\bullet$} \textcolor{yellow}{\Huge$\bullet$} 
    \textcolor{green}{\Huge$\bullet$}}%
  }{\textcolor{blue!30!gray}{\rule[-1ex]{3.5ex}{4\baselineskip}}}%
}
\begin{document}
\setstackEOL{\\}
\Longstack[l]{Score 21--30\\ Score 11--20\\ Score 1--10} \trafficlight
\end{document}

enter image description here

...or if no corresponding side-text is needed.

\documentclass{article}
\usepackage{stackengine,amssymb,xcolor}
\setstackgap{S}{1pt}
\savestack\trafficlight{%
  \stackinset{c}{}{c}{}{%
    \Shortstack{\textcolor{red}{$\bullet$} \textcolor{yellow}{$\bullet$} 
    \textcolor{green}{$\bullet$}}%
  }{\textcolor{blue!30!gray}{\rule{1.55ex}{4.2ex}}}%
}
\begin{document}
This is a \trafficlight.
\end{document}

enter image description here

5

Here is a short code with pstricks:

\documentclass[x11names, border = 5pt]{standalone}
\usepackage{pstricks-add}
\usepackage{auto-pst-pdf}

\begin{document}

\psset{fillstyle = solid}\everypsbox{\bfseries\textbullet\hspace{0.6em}Score }
\begin{psmatrix}[emnode = p, rowsep = 0.4cm]%
    [name = rlight] \\ [name = olight] \\ [name = glight]
    \ncbox[fillstyle = solid, fillcolor = SteelBlue3, linearc = 0.3, nodesepA = 0.7cm, nodesepB = 0.45cm, boxsize = 0.5]{rlight}{glight}
    \foreach \l/\colour in {rlight/red, olight/Orange1, glight/SpringGreen2} {\pscircle[fillcolor = \colour](\l){0.3cm}}
    \nput{180}{rlight}{\makebox[8cm][l]{21--30: high anaphylactic risk (Step 3)}}
    \nput{180}{olight}{\makebox[8cm][l]{11--20: medium anaphylactic risk (Step 2)}}
    \nput{180}{glight}{\makebox[8cm][l]{1--10: low anaphylactic risk (Step 1B/1A)}}
\end{psmatrix}

\end{document} 

enter image description here

3

For some reason nobody has animated the traffic light yet. You can use the animate package together with tikz:

\documentclass{article}
\usepackage{animate}
\usepackage{tikz}

\usetikzlibrary{positioning, fit, backgrounds}

\begin{document}
\begin{animateinline}[autoplay,loop]{2}
    \multiframe{3}{n=1+1}{
        \pgfmathsetmacro\tcolor{ifthenelse(\n==3,100,20)}
        \pgfmathsetmacro\mcolor{ifthenelse(\n==2,100,20)}
        \pgfmathsetmacro\bcolor{ifthenelse(\n==1,100,20)}
        \begin{tikzpicture}
            \node[circle,minimum size=5mm, anchor=center, draw=black, fill=red!\tcolor](top){};
            \node[below = 5mm of top,circle,minimum size=5mm, anchor=center, draw=black, fill=yellow!\mcolor](middle){};
            \node[below = 5mm of middle,circle,minimum size=5mm, anchor=center, draw=black, fill=green!\bcolor](bottom){};
            \node[right= 2mm of top] {High risk};
            \node[right= 2mm of middle] {Medium risk};
            \node[right= 2mm of bottom] {Low risk};
            \begin{scope}[on background layer]
                \node[draw,rounded corners,draw = blue!70,fill = blue!30,,fit=(top) (middle) (bottom)] {};
            \end{scope}
        \end{tikzpicture}
    }
\end{animateinline}

\end{document}

Result:

enter image description here

3
\documentclass[pstricks,border=1cm,dvipsnames]{standalone}
\begin{document}
\begin{pspicture}[fillstyle=solid](5,5)
    \psframe[fillcolor=NavyBlue,framearc=.2](2,5)
    \pscircle[fillcolor=green](1,1){.5}\rput(3.5,1){Score 1--10}
    \pscircle[fillcolor=yellow](1,2.5){.5}\rput(3.5,2.5){Score 11--20}
    \pscircle[fillcolor=red](1,4){.5}\rput(3.5,4){Score 21--30}
\end{pspicture}
\end{document}

enter image description here

Animation

Just in case you need an animation but without the Adobe Reader window.

\documentclass[pstricks,border=1cm,dvipsnames]{standalone}
\usepackage{multido}
\begin{document}
\multido{\i=1+1}{3}{%
\begin{pspicture}[fillstyle=solid](5,5)
    \psframe[fillcolor=NavyBlue,framearc=.2](2,5)
    \ifnum\i=3\relax
        \pscircle[fillcolor=green](1,1){.5}
    \else
        \pscircle[fillcolor=green!5](1,1){.5}
    \fi
    \ifnum\i=1\relax
        \pscircle[fillcolor=yellow](1,2.5){.5}
    \else
        \pscircle[fillcolor=yellow!5](1,2.5){.5}
    \fi
    \ifnum\i=2\relax
        \pscircle[fillcolor=red](1,4){.5}
    \else
        \pscircle[fillcolor=red!5](1,4){.5}
    \fi
    \rput[l](3,1){Score 1--10}
    \rput[l](3,2.5){Score 11--20}
    \rput[l](3,4){Score 21--30}
\end{pspicture}}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.