Debian Codegraph @

texmf-dist/tex/latex/tikzlings/tikzlings-bees.sty

raw
1 % !TeX root = ./examples/bee.tex
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %%
4 %% This package is part of the TikZlings package
5 %% A package to bring cute little animals and other beings into tikz
6 %% Maintained by samcarter
7 %%
8 %% Project repository and bug tracker:
9 %% https://github.com/samcarter/tikzlings
10 %%
11 %% Released under the LaTeX Project Public License v1.3c or later
12 %% See https://www.latex-project.org/lppl.txt
13 %%
14 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15 \ProvidesPackage{tikzlings-bees}[2025/12/11 version v2.5 Drawing bees in TikZ]
16
17 \RequirePackage{tikz}
18 \RequirePackage{tikzlings-addons}
19
20 \newcommand*{\bee}[1][]{%
21 \begin{scope}%
22 \tikzset{/bee/.cd,#1}%
23 \bee@draw%
24 \end{scope}%
25 \thing[#1]%
26 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27 \UseHook{tikzlings/bee/foreground}
28 \UseHook{tikzlings/foreground}
29 \csname beehookforeground\endcsname
30 \csname tikzlinghookforeground\endcsname
31 %
32 }
33
34 \newif\ifbee@threeD
35 \newif\ifbee@back
36 \newif\ifbee@contour
37 \newif\ifbee@openmouth
38
39 \NewHook{tikzlings/bee/background}
40 \NewHook{tikzlings/bee/belly}
41 \NewHook{tikzlings/bee/body}
42 \NewHook{tikzlings/bee/foreground}
43
44 \tikzset{
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46 %
47 % Pass unknown keys on to tikz
48 %
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 /bee/.search also={/tikz,/pgf,/thing},
51 /bee/.cd,
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 %
54 % body
55 %
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 body/.store in = \bee@body,
58 body = yellow!70!orange,
59 hands/.store in = \bee@hands,
60 hands = black,
61 hand/.forward to = /bee/hands,
62 wings/.store in = \bee@wings,
63 wings = blue!20!cyan!30!white,
64 wing/.forward to = /bee/wings,
65 stripes/.store in = \bee@stripes,
66 stripes = black,
67 stripe/.forward to = /bee/stripes,
68 antennas/.store in = \bee@antennas,
69 antennas = black,
70 antenna/.forward to = /bee/antennas,
71 eyes/.store in = \bee@eyes,
72 eyes = black,
73 eye/.forward to = /bee/eyes,
74 mouth/.store in = \bee@mouth,
75 mouth = black,
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 %
78 % options
79 %
80 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 openmouth/.code = \bee@openmouthtrue,
82 open mouth/.forward to = /bee/openmouth,
83 3D/.code = \bee@threeDtrue,
84 back/.code = \bee@backtrue,
85 contour/.code = \bee@contourtrue
86 \def\bee@contour{#1}
87 \def\bee@antennas{#1}
88 \def\bee@mouth{#1},
89 contour/.default = black,
90 outline/.forward to = /bee/contour,
91 }
92
93 \def\bee@draw{%
94 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95 %
96 % minimal bounding box size
97 %
98 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99 \path (-0.88,0.1) rectangle (0.88, 2.4);
100 %
101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102 %
103 % store the current scale factor
104 % from https://github.com/samcarter/tikzlings/issues/3#issuecomment-461373494
105 %
106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107 \pgfgettransformentries{\tmpscaleA}{\tmpscaleB}{\tmpscaleC}{\tmpscaleD}{\tmp}{\tmp}%
108 \pgfmathsetmacro{\scalingfactor}{sqrt(abs(\tmpscaleA*\tmpscaleD-\tmpscaleB*\tmpscaleC))*sqrt(abs((\pgf@xx/1cm)*(\pgf@yy/1cm)-(\pgf@xy/1cm)*(\pgf@yx/1cm)))}%
109 \pgfmathsetmacro{\xscalefactor}{\tmpscaleA}
110 \pgfmathsetmacro{\yscalefactor}{\tmpscaleD}
111 %
112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113 %
114 % switch between 2D, 3D and contours, from
115 % https://chat.stackexchange.com/transcript/message/45991801#45991801
116 %
117 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
118 \ifbee@threeD
119 \def\bee@part@draw[##1]{\shade[ball color=##1]}
120 \else% 3D
121 \ifbee@contour
122 \def\bee@part@draw[##1]{\draw[##1,\bee@contour,fill=white,line width=\scalingfactor*0.4pt]}
123 \else% contour
124 \def\bee@part@draw[##1]{\fill[##1]}
125 \fi% contour
126 \fi% 3D
127 %
128 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
129 %
130 % Body parts
131 %
132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133 %
134 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135 \UseHook{tikzlings/bee/background}
136 \UseHook{tikzlings/background}
137 \csname beehookbackground\endcsname
138 \csname tikzlinghookbackground\endcsname
139 %
140 \ifbee@back
141 %
142 % Antenna %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
143 \fill[\bee@antennas,rotate around={15:(-0.175,2.115)}] (-0.2,1.93) rectangle (-0.15,2.3);
144 \fill[\bee@antennas,rotate around={-15:(0.175,2.115)}] (0.2,1.93) rectangle (0.15,2.3);
145 \bee@part@draw[\bee@antennas] (-0.22,2.30) circle[radius=0.07];
146 \bee@part@draw[\bee@antennas] (0.22,2.30) circle[radius=0.07];
147 \else% back
148 % Wings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
149 \ifbee@contour
150 \bee@part@draw[\bee@wings] (0.5,0.8) circle[radius=0.35];
151 \bee@part@draw[\bee@wings] (0.45,1.25) circle[radius=0.35];
152 \bee@part@draw[\bee@wings] (-0.5,0.8) circle[radius=0.35];
153 \bee@part@draw[\bee@wings] (-0.45,1.25) circle[radius=0.35];
154 \else% contour
155 \fill[\bee@wings] (0.45,1.25) circle[radius=0.35] (0.5,0.8) circle[radius=0.35];
156 \fill[\bee@wings] (-0.45,1.25) circle[radius=0.35](-0.5,0.8) circle[radius=0.35];
157 \fi% contour
158 \fi% back
159 %
160 % Body %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
161 \bee@part@draw[\bee@body] (0,2.1) to[out=180,in=140,looseness=1.2] (-0.3,1.5) to[out=-110,in=180,looseness=1.2] (0,0.15) to[out=00,in=-65,looseness=1.2] (0.3,1.5) to[out=40,in=0,looseness=1.2] cycle;
162 \bee@part@draw[\bee@stripes] (-0.3845, 1.2427).. controls (-0.3978, 1.1967) and (-0.4102, 1.1508) .. (-0.4213, 1.1051).. controls (-0.339, 1.0724) and (-0.1703, 1.05) .. (0.025, 1.05).. controls (0.2024, 1.05) and (0.3578, 1.0685) .. (0.4466, 1.0964).. controls (0.4345, 1.1426) and (0.4206, 1.1889) .. (0.4053, 1.2351).. controls (0.3136, 1.2136) and (0.1774, 1.2) .. (0.025, 1.2).. controls (-0.1445, 1.2) and (-0.2941, 1.2169) .. (-0.3845, 1.2427) -- cycle(-0.4505, 0.9692).. controls (-0.4588, 0.9242) and (-0.4654, 0.88) .. (-0.4704, 0.8366).. controls (-0.4375, 0.7877) and (-0.2284, 0.75) .. (0.025, 0.75).. controls (0.2433, 0.75) and (0.4285, 0.778) .. (0.4966, 0.817).. controls (0.4925, 0.8629) and (0.4858, 0.9099) .. (0.4772, 0.9575).. controls (0.3973, 0.9236) and (0.2251, 0.9) .. (0.025, 0.9).. controls (-0.1973, 0.9) and (-0.3855, 0.929) .. (-0.4505, 0.9692) -- cycle(-0.475, 0.65) -- (-0.475, 0.5798).. controls (-0.4712, 0.5424) and (-0.465, 0.5067) .. (-0.4563, 0.4729).. controls (-0.3973, 0.4309) and (-0.2042, 0.4) .. (0.025, 0.4).. controls (0.2141, 0.4) and (0.3785, 0.421) .. (0.4635, 0.452).. controls (0.4809, 0.5028) and (0.4921, 0.5583) .. (0.4975, 0.6175).. controls (0.43, 0.5782) and (0.2442, 0.55) .. (0.025, 0.55).. controls (-0.2511, 0.55) and (-0.475, 0.5947) .. (-0.475, 0.65) -- cycle(-0.3628, 0.2869).. controls (-0.2871, 0.2009) and (-0.1703, 0.15) .. (-0.0, 0.15).. controls (0.1603, 0.15) and (0.2765, 0.1965) .. (0.3564, 0.2753).. controls (0.2681, 0.2596) and (0.1523, 0.25) .. (0.025, 0.25).. controls (-0.1315, 0.25) and (-0.2711, 0.2644) .. (-0.3628, 0.2869) -- cycle;
163 %
164 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
165 \UseHook{tikzlings/bee/belly}
166 \UseHook{tikzlings/belly}
167 \csname beehookbelly\endcsname
168 \csname tikzlinghookbelly\endcsname
169 %
170 % Show details only from the front %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
171 \ifbee@back
172 %
173 % Wings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
174 \ifbee@contour
175 \bee@part@draw[\bee@wings] (0.5,0.8) circle[radius=0.35];
176 \bee@part@draw[\bee@wings] (0.45,1.25) circle[radius=0.35];
177 \bee@part@draw[\bee@wings] (-0.5,0.8) circle[radius=0.35];
178 \bee@part@draw[\bee@wings] (-0.45,1.25) circle[radius=0.35];
179 \else% contour
180 \fill[\bee@wings] (0.45,1.25) circle[radius=0.35] (0.5,0.8) circle[radius=0.35];
181 \fill[\bee@wings] (-0.45,1.25) circle[radius=0.35](-0.5,0.8) circle[radius=0.35];
182 \fi% contour
183 \else% back
184 %
185 % Eyes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
186 \bee@part@draw[\bee@eyes] (-0.15,1.8) circle[radius=0.05];
187 \bee@part@draw[\bee@eyes] (0.15,1.8) circle[radius=0.05];
188 %
189 % Arms %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
190 \bee@part@draw[\bee@hands] (-0.25,0.88) circle[x radius=0.07,y radius=0.2, rotate=25];
191 \bee@part@draw[\bee@hands] (0.25,0.88) circle[x radius=0.07,y radius=0.2, rotate=-25];
192 %
193 % Mouth %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
194 \ifbee@openmouth
195 \filldraw[\bee@mouth,line width=\scalingfactor*0.4pt] (0.115, 1.6) arc [start angle=-40, end angle=-140, radius=0.16];
196 \else
197 \draw[\bee@mouth,line width=\scalingfactor*0.4pt] (0.115, 1.6) arc [start angle=-40, end angle=-140, radius=0.16];
198 \fi
199 %
200 % Antenna %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
201 \fill[\bee@antennas,rotate around={15:(-0.175,2.115)}] (-0.2,1.93) rectangle (-0.15,2.3);
202 \fill[\bee@antennas,rotate around={-15:(0.175,2.115)}] (0.2,1.93) rectangle (0.15,2.3);
203 \bee@part@draw[\bee@antennas] (-0.22,2.30) circle[radius=0.07];
204 \bee@part@draw[\bee@antennas] (0.22,2.30) circle[radius=0.07];
205 %
206 \fi% back
207 %
208 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
209 \UseHook{tikzlings/bee/body}
210 \UseHook{tikzlings/body}
211 \csname beehookbody\endcsname
212 \csname tikzlinghookbody\endcsname
213 %
214 }
215
216 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
217 %%
218 %% Documentation
219 %%
220 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
221 %\clearpage
222 %\section[Bee]{Beeing, the bee}
223 %
224 %\emph{The bee was kindly contributed by @marmot}
225 %
226 %\subsection{Package name}
227 %
228 %\begin{tcolorbox}[title={Package usage}]
229 %\begin{samcode}
230 %\usepackage{tikzlings-bees}
231 %\end{samcode}
232 %\end{tcolorbox}
233 %
234 %\subsection{Basic Usage}
235 %
236 %\begin{tcblisting}{title={Basic bee}}
237 %\bee
238 %\end{tcblisting}
239 %
240 %\subsection{Options}
241 %
242 %The basic bee can be modified by changing its colour:
243 %\begin{tcblisting}{}
244 %\bee[body=blue]
245 %\end{tcblisting}
246 %
247 %In addition to the colour of the body, the colour of various body parts can be adjusted:
248 %\begin{tcblisting}{title={Antenna colour}}
249 %\bee[antennas=red]
250 %\end{tcblisting}
251 %\begin{tcblisting}{title={Eye colour}}
252 %\bee[eyes=red]
253 %\end{tcblisting}
254 %\begin{tcblisting}{title={Mouth colour}}
255 %\bee[mouth=red]
256 %\end{tcblisting}
257 %\begin{tcblisting}{title={Wing colour}}
258 %\bee[wings=red]
259 %\end{tcblisting}
260 %\begin{tcblisting}{title={Hand colour}}
261 %\bee[hands=red]
262 %\end{tcblisting}
263 %\begin{tcblisting}{title={Stripe colour}}
264 %\bee[stripes=red]
265 %\end{tcblisting}
266 %
267 % The bee can open its mouth:
268 %\begin{tcblisting}{title={Open mouth}}
269 %\bee[openmouth]
270 %\end{tcblisting}
271 %
272 %To view the bee from behind:
273 %\begin{tcblisting}{title={back view}}
274 %\bee[back]
275 %\end{tcblisting}
276 %
277 %The key \saminline|3D| will make the bee 3-dimensional:
278 %\begin{tcblisting}{title={3D view}}
279 %\bee[3D]
280 %\end{tcblisting}
281 %
282 %And finally the \saminline|contour| key will only draw the outlines:
283 %\begin{tcblisting}{title={Contours}}
284 %\bee[contour=black]
285 %\end{tcblisting}