答案1
这不太像目标图像,但确实具有一定的优势。
[此处双关语是有意为之。]
该装饰明显盗用了renard 的回答。我之所以使用这个答案,是因为它声称与圆圈兼容,我计划使用一些圆圈。然而,事实证明,下面的代码完全没有圆圈。我稍微修改了装饰代码,尽管不知道它是什么意思,但实际上只是为了避免额外的依赖。
但结果完全是我的错,不应该责怪装饰的作者,他显然从来没有想过要以这种方式滥用它。
像往常一样,这棵树的发生显然完全归咎于我。
买者自负...
\documentclass[border=0pt,tikz]{standalone}
\usepackage{forest}
\usepackage[sf={lining},rm={lining},tt={lining}]{cfr-lm}
\usetikzlibrary{decorations,backgrounds}
% ref.: decoration is from renard's answer at https://tex.stackexchange.com/a/218483/ but avoid depending on ifthen package
\makeatletter
\pgfdeclaredecoration{penciline}{initial}{
\state{initial}[width=+\pgfdecoratedinputsegmentremainingdistance,
auto corner on length=1pt,
]{
\pgfmathparse{equal(\penciline@jagratio,0) ? "0" : "1"}
\ifnum\pgfmathresult=0
\pgfpathcurveto%
{% 1st control point
\pgfpoint
{\pgfdecoratedinputsegmentremainingdistance/2}
{2*rnd*\pgfdecorationsegmentamplitude}
}
{%% 2nd control point
\pgfpoint
%% Make sure random number is always between origin and target points
{\pgfdecoratedinputsegmentremainingdistance/2}
{2*rnd*\pgfdecorationsegmentamplitude}
}
{% 2nd point (1st one is implicit)
\pgfpointadd
{\pgfpointdecoratedinputsegmentlast}
{\pgfpoint{0*rand*1pt}{0*rand*1pt}}
}
\else
\pgfpathcurveto%
{% 1st control point
\pgfpoint
{\pgfdecoratedinputsegmentremainingdistance*rnd*1pt}
{\penciline@jagratio*
rand*\pgfdecorationsegmentamplitude}
}
{%% 2nd control point
\pgfpoint
%% Make sure random number is always between origin and target points
{(.5+0.25*rand)*\pgfdecoratedinputsegmentremainingdistance}
{\penciline@jagratio*
rand*\pgfdecorationsegmentamplitude}
}
{% 2nd point (1st one is implicit)
\pgfpointadd
{\pgfpointdecoratedinputsegmentlast}
{\pgfpoint{rand*1pt}{rand*1pt}}
}
\fi
}
\state{final}{}
}
\tikzset{
penciline/.code = {
\tikzset{
penciline/.cd,
#1,
},
},
penciline/.cd,
jag ratio/.store in=\penciline@jagratio,
jag ratio=5,
}
\makeatother
\begin{document}
\begin{forest}
bloody node/.style={
text=#1,
text opacity=1,
ball color=white,
fill opacity=.15,
rounded corners=5pt,
},
for tree={
align=center,
parent anchor=south,
child anchor=north,
if={isodd(n_children())}{
for children={
if={n()==int((n_children("!u")+1)/2)}{
calign with current
}{}
}
}{},
font=\tistyle\bfseries\scshape,
edge={decorate, decoration=penciline, penciline={jag ratio=4}, ultra thin, inner color=red, outer color=red!25!black, draw=red!15!black, rounded corners=1mm},
l sep+=5mm,
s sep+=5mm,
},
where level=0{}{
if={n()>int((n_children("!u")+1)/2)}{
edge path={
\noexpand\path [\forestoption{edge}] (!u.parent anchor) -- ++(0,-2.5mm) coordinate (!u second parent) [bend left=10] to (!u second parent -| .child anchor) [bend left] to (.child anchor)\forestoption{edge label} [bend right] to (!u second parent -| .child anchor) [bend right=10] to (!u second parent) -- cycle;
},
}{
edge path={
\noexpand\path [\forestoption{edge}] (!u.parent anchor) -- ++(0,-2.5mm) coordinate (!u second parent) [bend right=10] to (!u second parent -| .child anchor) [bend right] to (.child anchor)\forestoption{edge label} [bend left] to (!u second parent -| .child anchor) [bend left=10] to (!u second parent) -- cycle;
},
},
}
[Mandy\\Evans, bloody node=blue, tikz+={\scoped[on background layer]\fill (current bounding box.south west) rectangle (current bounding box.north east);}
[Gerald\\Evans, for tree={bloody node=blue}]
[Catherine\\Evans, for tree={bloody node=red}
[Arnold\\Evans]
[Donald\\Evans]
[Amy\\Akrington
[Basil\\Pasilicous]
[Divula\\Akrington
[Livia\\Arlington-Likrinton]
]
]
]
[Lima\\Peterson, for tree={bloody node=green}
[Esmeralda\\Bobbington]
[Tivulus\\Kadaverula]
]
]
\end{forest}
\end{document}
答案2
这是使用 metapost 的一次尝试。首先我将展示结果(仅针对行,而不是文本)。
主要思想是将每条路径分成小段,并用稍微随机的笔绘制每个段。然后对整个路径也添加一点随机性。
\startMPdefinitions
pen randompen;
randompen_n := 100;
randompen_a := 0.75;
randompen_s := 3bp;
sketch_amount := 0.5bp;
def basicpen =
((-0.5,0.5) -- (0.5,0.5) --
(0.5,-0.5) .. (0, -0.5 randomized randompen_a)
.. (-0.5, 0.5) -- cycle) rotated 45
enddef;
def bloodydraw expr p =
for i = 0 step 1/randompen_n until length p:
randompen := makepen (basicpen) scaled randompen_s;
draw subpath (i, i + 1/randompen_n) of p randomized sketch_amount withpen randompen _op_;
endfor
enddef;
\stopMPdefinitions
\starttext
\startMPpage[offset=2mm]
u := 1cm ;
z[0] = (0u,0u);
z[-1] = (-1u,-1u); z[1] = (1u,-1u);
z[-2] = (-2u,-1u); z[2] = (2u,-1u);
z[-20] = (-2u,-2u); z[20] = (2u,-2u);
z[-10] = (-1u,-2u); z[10] = (1u,-2u);
drawoptions(withcolor 0.7red);
bloodydraw z[0] -- 0.5[z[-1],z[1]];
bloodydraw z[-2] -- z[2];
for i = -2,-1,1,2 :
bloodydraw z[i] -- z[i*10];
endfor;
\stopMPpage
\stoptext
使用此技术绘制完整的图像留给读者作为练习:-)