我想画出 F_2(两个生成器上的自由群)的凯莱图,并进行特别考虑。也就是说,索引 2 子群(偶数次移动到达的顶点和偶数次垂直/水平移动到达的顶点)应使用不同的颜色。我发现了这篇精彩的帖子TikZ 中自由群的凯莱图关于创建图表,虽然似乎没有一个能轻易满足我的要求。有人能帮忙吗?
答案1
此代码来自展示示例tikzmath
结果
代码
\documentclass[tikz,border=10pt]{standalone} %built from http://latex-community.org/know-how/513-tikz-math
\usetikzlibrary{math,backgrounds}
\begin{document}
% -------------------
% styles of the beads
% -------------------
\tikzset
{
coloredBeadRoot/.style=
{
circle,
},
coloredBead/.style=
{
coloredBeadRoot,
fill=\color,
scale=\beadsize*\scale,
}
}
\begin{tikzpicture}[scale=.3pt]
\tikzmath{
% --------------------------
% the parameters of the tree
% --------------------------
\power=2.3; % the scale base factor
\deviation=90; % the angle between the 3 child edges
\numsteps=4; % number of levels
let \startcolor=black; % the start color
let \endcolor=black; % the end color
let \oddcolor=red; % the odd bead color
let \evencolor=blue; % the even bead color
\beadsize=.2; % the scale of colored beads
% -------------------------------------------------------------------------
% the function that draw one edge and call itself to draw the 3 child edges
% -------------------------------------------------------------------------
function Branch(\x,\y,\rotate,\step){
\step=\step-1; % stops drawing if step < 0
if (\step >= 0) then %
{
\mix = int(100*\step/(\numsteps-1)); % the color mix parameter is in [0,100]
\scale = \power^\step; % the scale factor
{ % "print" the tikz command that draw the edge
\scoped[on background layer]
\draw
[
shift={(\x pt,\y pt)},
rotate=\rotate,
scale=\scale,
color=\startcolor!\mix!\endcolor,
line width=\scale*.1 pt,
line cap=round,
]
(0,0)--(1,0) coordinate(newbase) ;
};
% -----------------------
% place the colored beads
% -----------------------
if (isodd(\step)) then %
{
let \color=\oddcolor;
}
else
{
let \color=\evencolor;
};
{
\node [coloredBead] at (newbase) {} ;
};
% --------------
% recursive call
% --------------
coordinate \b;
\b1 = (newbase); % the new base point
for \a in {-\deviation,0,\deviation}%
{
Branch(\bx1,\by1,mod(\rotate+\a,360),\step); % draw one child edge
};
};
};
% --------------
% draw root bead
% --------------
{
\node
[
coloredBeadRoot,
fill=\evencolor,
scale=\beadsize*\power^\numsteps,
]
at (0,0) {};
};
% ----------------------
% draw the four branches
% ----------------------
for \angle in {0,90,180,-90}{
Branch(0,0,\angle,\numsteps);
};
}
\end{tikzpicture}
\end{document}
干杯