3

I was wondering how to recreate the following image in Tikz. Where the main problem is creating the circles with different horizontal shades.

How can I recreate this image with the distinct shaded/coloured circles?

c

1 Answer 1

5

You can define the colored circle as a node with a path picture that colors some 1/n fractions of the horizontal distance. This style is called cc and cc=1,...,5 produces the colored circles. The coloring is dependent on the column index in a matrix, which also can be used to create O1,...,O5 automagically.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{arrows.meta,matrix}
\begin{document}
\begin{tikzpicture}[font=\sffamily,>={Latex[round,length=3pt]},
    marr/.style={semithick,->,shorten >=2pt,shorten <=1.5pt},
    cc/.style={circle,draw,inner sep=1ex,
        path picture={\foreach \XX in {1,...,#1}
        {\path[fill=c\the\numexpr#1+1-\XX\relax] (path picture bounding box.south west) rectangle
        ([xshift={-2pt+2*(\pgfkeysvalueof{/pgf/inner xsep}+3pt+\pgflinewidth)/\XX}]path picture bounding box.north west);}}}]
\definecolor{c1}{RGB}{44,57,66}
\definecolor{c2}{RGB}{91,148,122}
\definecolor{c3}{RGB}{213,180,97}
\definecolor{c4}{RGB}{207,134,84}
\definecolor{c5}{RGB}{186,78,70}
\matrix[matrix of nodes,nodes in empty cells,row sep=1em,
 row 1/.style={nodes={execute at begin node=O\the\pgfmatrixcurrentcolumn}},
 row 2/.style={nodes={cc=\the\pgfmatrixcurrentcolumn}},
 row 3/.style={nodes={text=c\the\pgfmatrixcurrentcolumn,
 text width={width("What")},align=center}}] (mat)
 { & & & & \\
  & & & & \\
  What & time & is & it & ? \\};
\foreach \X in {1,...,5} {
  \draw[marr] (mat-2-\X) -- (mat-1-\X);
  \draw[marr] (mat-3-\X) -- (mat-2-\X);
  \ifnum\X<5
  \draw[marr] (mat-2-\X) -- (mat-2-\the\numexpr\X+1);
  \fi
}; 
\end{tikzpicture}
\end{document}

enter image description here

3
  • 2
    The answer to this question is obviously "Hibernation Time".
    – user194703
    Commented Apr 10, 2020 at 23:36
  • Thanks a bunch! this is perfect. Looks like magic to me but if it works, it works
    – Rien
    Commented Apr 10, 2020 at 23:41
  • 1
    @Rien You're welcome! (And you seem to be surprised that catcodes work. They get used all time. ;-)
    – user194703
    Commented Apr 11, 2020 at 0:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .