Tree edges different coloring
Very similar to Andrew's nice answer except that parents and children have different colors. EDIT: removed a superfluous \index
, big thanks to Andrew! @nd EDIT: Simplification with \pgfkeysalso
.
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{trees,snakes}
\begin{document}
\pagestyle{empty}
\xdef\mycolor{black}
\xdef\ColorList{{"red","green!60!black","blue"}}
\tikzset{level 1/.style={level distance= 32mm,sibling angle=120},
level 2/.style={level distance= 16mm,sibling angle=60},
level 3/.style={level distance = 12mm,sibling angle=30},
every node/.append style={fill},
my color/.code={\pgfmathparse{\ColorList[mod(#1,3)]}
\pgfkeysalso{/tikz/color/.expanded=\pgfmathresult}}}
\begin{tikzpicture}[grow cyclic,shape=circle,very thick,level distance=13mm,
cap=round]
\node {} child [my color=\A] foreach \A in {0,1,2}
{ node {} child [my color=\A+\B+1] foreach \B in {0,1}
{ node {} child [my color=\A+\B+\C+2] foreach \C in {0,1}
{ node {} }
}
};
\end{tikzpicture}
\end{document}
If you want each vertex to have valence 3 then you should loop over only two colours for the child nodes. This produces:
Here is the modified code:
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{trees,snakes}
\begin{document}
\pagestyle{empty}
\tikzstyle{level 1}=[level distance= 32mm,sibling angle=120]
\tikzstyle{level 2}=[level distance= 16mm,sibling angle=60]
\tikzstyle{level 3}=[level distance = 12mm,sibling angle=30]
\tikzstyle{every node}=[fill]
%\tikzstyle{edge from parent}=[segment length=1mm,
% segment angle=10,draw]
\begin{tikzpicture}[grow cyclic,shape=circle,very thick,level distance=13mm,
cap=round]
\node {} child [color=\A] foreach \A in {red,green,blue}
{ node {} child [color=\A!50!\B] foreach \B in {red, green}
{ node {} child [color=\A!50!\B!50!\C] foreach \C in {red,green}
{ node {} }
}
};
\end{tikzpicture}
\end{document}