答案1
pic
每个基本图形都是通过元素创建的bird
;它基于等边三角形,正如@Andrew Stacey 解释的那样。然后,还有两个pic
元素:flock
由六个组成鸟类由flocks
七部分组成羊群. 该图由七幅组成flocks
。
这些常数按照三角顺序定义构成鸟的点。
代码
\documentclass[border=1cm, 11pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{math, calc}
\begin{document}
\tikzmath{
real \r, \a1, \d1, \a2, \d2, \a3, \d3, \a4, \d4, \b, \e;
\r = 1; \b = 5; \e = .75*\r;
\a1 = 40; \a2 = 15; \a3 = 17; \a4 = \a1;
\d1 = .4*\r; \d2 = .37*\r; \d3 = .65*\r; \d4 = \d3;
}
\tikzset{
pics/bird/.style 2 args={% color, fill color
code={%
\draw[#1, fill=#2!20]
(0, 0) -- +(-\a1: \d1) -- +(-\a2: \d2)
-- +(-\a3: \d3) -- +(-\a4: \d4) -- +(-30: \r)
{[rounded corners=2pt] -- +(\b: \e) -- +($(0: 1.732*\r) -(\b: \e)$)}
-- +(60 -30: \r) -- +(60 -\a4: \d4) -- +(60 -\a3: \d3)
-- +(60 -\a2: \d2) -- +(60 -\a1: \d1) -- cycle;
}
},
pics/flock/.style 2 args={% color, fill color
code={%
\foreach \i in {0, 2, 4}{%
\path (0, 0) pic[rotate={60*\i}] {bird={#1}{#1}};
\path (0, 0) pic[rotate={60*(\i +1)}] {bird={#1}{#2}};
}
}
},
pics/flocks/.style 2 args={% color, fill color
code={%
\path (0, 0) pic {flock={#1}{#2}};
\foreach \i in {0, 1, ..., 5}{%
\path (\i*60: 1.732*\r) pic {flock={#1}{#2}};
}
}
}
}
\begin{tikzpicture}
\path (0, 0) pic {flocks={violet}{white}};
\foreach \i in {0, 2, 4}{%
\path[rotate={\i*60}] ($(0: 1.732*\r) +(30: 3*\r)$) pic {flocks={red}{white}};
}
\foreach \i in {1, 3, 5}{%
\path[rotate={\i*60}]
($(0: 1.732*\r) +(30: 3*\r)$) pic {flocks={green!50!blue}{white}};
}
\end{tikzpicture}
\end{document}