Debian Codegraph @

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

raw
1 % !TeX root = ./examples/bug.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-bugs}[2025/12/11 version v2.5 Drawing bugs in TikZ]
16
17 \RequirePackage{tikz}
18 \RequirePackage{tikzlings-addons}
19
20 \newcommand*{\bug}[1][]{%
21 \begin{scope}%
22 \tikzset{/bug/.cd,#1}%
23 \bug@draw%
24 \end{scope}%
25 \thing[#1]%
26 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27 \UseHook{tikzlings/bug/foreground}
28 \UseHook{tikzlings/foreground}
29 \csname bughookforeground\endcsname
30 \csname tikzlinghookforeground\endcsname
31 %
32 }
33
34 \newif\ifbug@threeD
35 \newif\ifbug@leftstep
36 \newif\ifbug@rightstep
37 \newif\ifbug@back
38 \newif\ifbug@contour
39 \newif\ifbug@openmouth
40
41 \NewHook{tikzlings/bug/background}
42 \NewHook{tikzlings/bug/belly}
43 \NewHook{tikzlings/bug/body}
44 \NewHook{tikzlings/bug/foreground}
45
46 \tikzset{
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48 %
49 % Pass unknown keys on to tikz
50 %
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 /bug/.search also={/tikz,/pgf,/thing},
53 /bug/.cd,
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 %
56 % body
57 %
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59 body/.store in = \bug@body,
60 body = black!90!white,
61 arms/.store in = \bug@arms,
62 arms = red!80!black,
63 arm/.forward to = /bug/arms,
64 wings/.store in = \bug@wings,
65 wings = red!80!black,
66 wing/.forward to = /bug/wings,
67 dots/.store in = \bug@dots,
68 dots = black!90!white,
69 dot/.forward to = /bug/dots,
70 antennas/.store in = \bug@antennas,
71 antennas = red!80!black,
72 antenna/.forward to = /bug/antennas,
73 eyes/.store in = \bug@eyes,
74 eyes = white,
75 eye/.forward to = /bug/eyes,
76 pupils/.store in = \bug@pupils,
77 pupils = black,
78 pupil/.forward to = /bug/pupils,
79 mouth/.store in = \bug@mouth,
80 mouth = red,
81 feet/.store in = \bug@feet,
82 feet = red!80!black,
83 foot/.forward to = /bug/feet,
84 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85 %
86 % options
87 %
88 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89 3D/.code = \bug@threeDtrue,
90 leftstep/.code = \bug@leftsteptrue,
91 left step/.forward to = /bug/leftstep,
92 rightstep/.code = \bug@rightsteptrue,
93 right step/.forward to = /bug/rightstep,
94 openmouth/.code = \bug@openmouthtrue,
95 open mouth/.forward to = /bug/openmouth,
96 back/.code = \bug@backtrue,
97 contour/.code = \bug@contourtrue
98 \def\bug@contour{#1}
99 \def\bug@antennas{#1}
100 \def\bug@mouth{#1},
101 contour/.default = black,
102 outline/.forward to = /bug/contour,
103 }
104
105 \def\bug@draw{%
106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107 %
108 % minimal bounding box size
109 %
110 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111 \path (-0.92,0.02) rectangle (0.92, 2.36);
112 %
113 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114 %
115 % store the current scale factor
116 % from https://github.com/samcarter/tikzlings/issues/3#issuecomment-461373494
117 %
118 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
119 \pgfgettransformentries{\tmpscaleA}{\tmpscaleB}{\tmpscaleC}{\tmpscaleD}{\tmp}{\tmp}%
120 \pgfmathsetmacro{\scalingfactor}{sqrt(abs(\tmpscaleA*\tmpscaleD-\tmpscaleB*\tmpscaleC))*sqrt(abs((\pgf@xx/1cm)*(\pgf@yy/1cm)-(\pgf@xy/1cm)*(\pgf@yx/1cm)))}%
121 \pgfmathsetmacro{\xscalefactor}{\tmpscaleA}
122 \pgfmathsetmacro{\yscalefactor}{\tmpscaleD}
123 %
124 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
125 %
126 % switch between 2D, 3D and contours, from
127 % https://chat.stackexchange.com/transcript/message/45991801#45991801
128 %
129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130 \ifbug@threeD
131 \def\bug@part@draw[##1]{\shade[ball color=##1]}
132 \else% 3D
133 \ifbug@contour
134 \def\bug@part@draw[##1]{\draw[##1,\bug@contour,fill=white,line width=\scalingfactor*0.4pt]}
135 \else% contour
136 \def\bug@part@draw[##1]{\fill[##1]}
137 \fi% contour
138 \fi% 3D
139 %
140 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141 %
142 % Body parts
143 %
144 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
145 %
146 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
147 \UseHook{tikzlings/bug/background}
148 \UseHook{tikzlings/background}
149 \csname bughookbackground\endcsname
150 \csname tikzlinghookbackground\endcsname
151 %
152 \ifbug@back
153 %
154 % Antenna %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
155 \draw[\bug@antennas,line width=\scalingfactor*0.8pt] (0.1134, 1.911) .. controls (0.0917, 2.0537) and (0.0986, 2.1999) .. (0.1608, 2.2816) .. controls (0.245, 2.3919) and (0.3278, 2.3011) .. (0.3272, 2.2192) .. controls (0.3266, 2.1341) and (0.2237, 2.0423) .. (0.1978, 2.1538);
156 \draw[\bug@antennas,line width=\scalingfactor*0.8pt] (-0.1134, 1.911) .. controls (-0.0917, 2.0537) and (-0.0986, 2.1999) .. (-0.1608, 2.2816) .. controls (-0.245, 2.3919) and (-0.3278, 2.3011) .. (-0.3272, 2.2192) .. controls (-0.3266, 2.1341) and (-0.2237, 2.0423) .. (-0.1978, 2.1538);
157 \else% back
158 %
159 % Wings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
160 \bug@part@draw[\bug@wings] (-0.0955, 1.4222) .. controls (-0.2086, 1.6765) and (-0.692, 1.2508) .. (-0.8174, 1.0023) .. controls (-0.9304, 0.7786) and (-0.9533, 0.379) .. (-0.7355, 0.2548) .. controls (-0.5988, 0.1768) and (-0.4043, 0.3269) .. (-0.3054, 0.4494) .. controls (-0.097, 0.7075) and (0.0589, 1.0749) .. (-0.0955, 1.4222) -- cycle;
161 \bug@part@draw[\bug@wings] (0.0955, 1.4222) .. controls (0.2086, 1.6765) and (0.692, 1.2508) .. (0.8174, 1.0023) .. controls (0.9304, 0.7786) and (0.9533, 0.379) .. (0.7355, 0.2548) .. controls (0.5988, 0.1768) and (0.4043, 0.3269) .. (0.3054, 0.4494) .. controls (0.097, 0.7075) and (-0.0589, 1.0749) .. (0.0955, 1.4222) -- cycle;
162 \ifbug@contour
163 \bug@part@draw[\bug@dots] (-0.2,0.85) circle [radius=0.08] (-0.5,0.8) circle [radius=0.08] (-0.8,0.75) circle [radius=0.08] (-0.35,0.6) circle [radius=0.08] (-0.65,0.5) circle [radius=0.08] (-0.3,1.05) circle [radius=0.08] (-0.6,1.1) circle [radius=0.08] (-0.35,1.35) circle [radius=0.08] (0.2,0.85) circle [radius=0.08] (0.5,0.8) circle [radius=0.08] (0.8,0.75) circle [radius=0.08] (0.35,0.6) circle [radius=0.08] (0.65,0.5) circle [radius=0.08] (0.3,1.05) circle [radius=0.08] (0.6,1.1) circle [radius=0.08] (0.35,1.35) circle [radius=0.08];
164 \else% contour
165 \fill[\bug@dots] (-0.2,0.85) circle [radius=0.08] (-0.5,0.8) circle [radius=0.08] (-0.8,0.75) circle [radius=0.08] (-0.35,0.6) circle [radius=0.08] (-0.65,0.5) circle [radius=0.08] (-0.3,1.05) circle [radius=0.08] (-0.6,1.1) circle [radius=0.08] (-0.35,1.35) circle [radius=0.08] (0.2,0.85) circle [radius=0.08] (0.5,0.8) circle [radius=0.08] (0.8,0.75) circle [radius=0.08] (0.35,0.6) circle [radius=0.08] (0.65,0.5) circle [radius=0.08] (0.3,1.05) circle [radius=0.08] (0.6,1.1) circle [radius=0.08] (0.35,1.35) circle [radius=0.08];
166 \fi% contour
167 \fi% back
168 %
169 % Feet %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
170 \ifbug@leftstep
171 \bug@part@draw[\bug@feet] (-0.2,0.12) ellipse[x radius=0.18, y radius=0.06];
172 \else% step
173 \bug@part@draw[\bug@feet] (-0.2,0.1) ellipse[x radius=0.18, y radius=0.06];
174 \fi% step
175 \ifbug@rightstep
176 \bug@part@draw[\bug@feet] (0.2,0.12) ellipse[x radius=0.18, y radius=0.06];
177 \else% step
178 \bug@part@draw[\bug@feet] (0.2,0.1) ellipse[x radius=0.18, y radius=0.06];
179 \fi% step
180 %
181 % Body %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
182 \bug@part@draw[\bug@body] ( 0.55, 0.75) .. controls ( 0.55, 0.40) and ( 0.55, 0.08) .. ( 0.00, 0.08) .. controls (-0.55, 0.08) and (-0.55, 0.40) .. (-0.55, 0.75) .. controls (-0.55, 1.13) and (-0.30, 1.44) .. ( 0.00, 1.44) .. controls ( 0.30, 1.44) and ( 0.55, 1.13) .. ( 0.55, 0.75) -- cycle;
183 %
184 % Head %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
185 \bug@part@draw[\bug@body] (0,1.7) circle [radius=0.37];
186 %
187 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
188 \UseHook{tikzlings/bug/belly}
189 \UseHook{tikzlings/belly}
190 \csname bughookbelly\endcsname
191 \csname tikzlinghookbelly\endcsname
192 %
193 % Show details only from the front %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
194 \ifbug@back
195 %
196 % Wings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
197 \bug@part@draw[\bug@wings] (-0.0955, 1.4222) .. controls (-0.2086, 1.6765) and (-0.692, 1.2508) .. (-0.8174, 1.0023) .. controls (-0.9304, 0.7786) and (-0.9533, 0.379) .. (-0.7355, 0.2548) .. controls (-0.5988, 0.1768) and (-0.4043, 0.3269) .. (-0.3054, 0.4494) .. controls (-0.097, 0.7075) and (0.0589, 1.0749) .. (-0.0955, 1.4222) -- cycle;
198 \bug@part@draw[\bug@wings] (0.0955, 1.4222) .. controls (0.2086, 1.6765) and (0.692, 1.2508) .. (0.8174, 1.0023) .. controls (0.9304, 0.7786) and (0.9533, 0.379) .. (0.7355, 0.2548) .. controls (0.5988, 0.1768) and (0.4043, 0.3269) .. (0.3054, 0.4494) .. controls (0.097, 0.7075) and (-0.0589, 1.0749) .. (0.0955, 1.4222) -- cycle;
199 \ifbug@contour
200 \bug@part@draw[\bug@dots] (-0.2,0.85) circle [radius=0.08] (-0.5,0.8) circle [radius=0.08] (-0.8,0.75) circle [radius=0.08] (-0.35,0.6) circle [radius=0.08] (-0.65,0.5) circle [radius=0.08] (-0.3,1.05) circle [radius=0.08] (-0.6,1.1) circle [radius=0.08] (-0.35,1.35) circle [radius=0.08] (0.2,0.85) circle [radius=0.08] (0.5,0.8) circle [radius=0.08] (0.8,0.75) circle [radius=0.08] (0.35,0.6) circle [radius=0.08] (0.65,0.5) circle [radius=0.08] (0.3,1.05) circle [radius=0.08] (0.6,1.1) circle [radius=0.08] (0.35,1.35) circle [radius=0.08];
201 \else% contour
202 \fill[\bug@dots] (-0.2,0.85) circle [radius=0.08] (-0.5,0.8) circle [radius=0.08] (-0.8,0.75) circle [radius=0.08] (-0.35,0.6) circle [radius=0.08] (-0.65,0.5) circle [radius=0.08] (-0.3,1.05) circle [radius=0.08] (-0.6,1.1) circle [radius=0.08] (-0.35,1.35) circle [radius=0.08] (0.2,0.85) circle [radius=0.08] (0.5,0.8) circle [radius=0.08] (0.8,0.75) circle [radius=0.08] (0.35,0.6) circle [radius=0.08] (0.65,0.5) circle [radius=0.08] (0.3,1.05) circle [radius=0.08] (0.6,1.1) circle [radius=0.08] (0.35,1.35) circle [radius=0.08];
203 \fi% contour
204 \else% back
205 %
206 % Eyes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
207 \bug@part@draw[\bug@eyes] (0.13,1.75) ellipse[x radius=0.067, y radius=0.085];
208 \bug@part@draw[\bug@eyes] (-0.13,1.75) ellipse[x radius=0.067, y radius=0.085];
209 \bug@part@draw[\bug@pupils] (0.12,1.73) ellipse[x radius=0.019, y radius=0.029];
210 \bug@part@draw[\bug@pupils] (-0.12,1.73) ellipse[x radius=0.019, y radius=0.029];
211 %
212 % Arms %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
213 \bug@part@draw[\bug@arms] (-0.25,0.88) circle[x radius=0.07,y radius=0.18, rotate=35];
214 \bug@part@draw[\bug@arms] (0.25,0.88) circle[x radius=0.07,y radius=0.18, rotate=-35];
215 %
216 % Mouth %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
217 \ifbug@openmouth
218 \filldraw[\bug@mouth,line width=\scalingfactor*0.4pt] (0.115, 1.56) arc [start angle=-40, end angle=-140, radius=0.16];
219 \else
220 \draw[\bug@mouth,line width=\scalingfactor*0.4pt] (0.115, 1.56) arc [start angle=-40, end angle=-140, radius=0.16];
221 \fi
222 %
223 % Antenna %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
224 \draw[\bug@antennas,line width=\scalingfactor*0.8pt] (0.1134, 1.911) .. controls (0.0917, 2.0537) and (0.0986, 2.1999) .. (0.1608, 2.2816) .. controls (0.245, 2.3919) and (0.3278, 2.3011) .. (0.3272, 2.2192) .. controls (0.3266, 2.1341) and (0.2237, 2.0423) .. (0.1978, 2.1538);
225 \draw[\bug@antennas,line width=\scalingfactor*0.8pt] (-0.1134, 1.911) .. controls (-0.0917, 2.0537) and (-0.0986, 2.1999) .. (-0.1608, 2.2816) .. controls (-0.245, 2.3919) and (-0.3278, 2.3011) .. (-0.3272, 2.2192) .. controls (-0.3266, 2.1341) and (-0.2237, 2.0423) .. (-0.1978, 2.1538);
226 %
227 \fi% back
228 %
229 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
230 \UseHook{tikzlings/bug/body}
231 \UseHook{tikzlings/body}
232 \csname bughookbody\endcsname
233 \csname tikzlinghookbody\endcsname
234 %
235 }
236
237 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
238 %%
239 %% Documentation
240 %%
241 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
242 %\clearpage
243 %\section[Bug]{Marie, the bug}
244 %
245 %\emph{For a French girl who likes ladybugs -- the name comes from the German word for ladybug ``Marienkäfer''}
246 %
247 %\subsection{Package name}
248 %
249 %\begin{tcolorbox}[title={Package usage}]
250 %\begin{samcode}
251 %\usepackage{tikzlings-bugs}
252 %\end{samcode}
253 %\end{tcolorbox}
254 %
255 %\subsection{Basic Usage}
256 %
257 %\begin{tcblisting}{title={Basic bug}}
258 %\bug
259 %\end{tcblisting}
260 %
261 %\subsection{Options}
262 %
263 %The basic bug can be modified by changing its colour:
264 %\begin{tcblisting}{title={Body colour}}
265 %\bug[body=blue]
266 %\end{tcblisting}
267 %
268 %In addition to the colour of the body, the colour of various body parts can be adjusted:
269 %\begin{tcblisting}{title={Antenna Colour}}
270 %\bug[antennas=blue]
271 %\end{tcblisting}
272 %\begin{tcblisting}{title={Eye colour}}
273 %\bug[eyes=blue]
274 %\end{tcblisting}
275 %\begin{tcblisting}{title={Pupil colour}}
276 %\bug[pupils=blue]
277 %\end{tcblisting}
278 %\begin{tcblisting}{title={Mouth colour}}
279 %\bug[mouth=blue]
280 %\end{tcblisting}
281 %\begin{tcblisting}{title={Arm colour}}
282 %\bug[arms=blue]
283 %\end{tcblisting}
284 %\begin{tcblisting}{title={Wing colour}}
285 %\bug[wings=blue]
286 %\end{tcblisting}
287 %\begin{tcblisting}{title={Foot colour}}
288 %\bug[feet=blue]
289 %\end{tcblisting}
290 %
291 % The bug can open its mouth:
292 %\begin{tcblisting}{title={Open mouth}}
293 %\bug[openmouth]
294 %\end{tcblisting}
295 %
296 %And the bug can lift its legs:
297 %\begin{tcblisting}{title={Walking}}
298 %\bug[leftstep]
299 %\bug[rightstep,xshift=2cm]
300 %\end{tcblisting}
301 %
302 %To view the bug from behind:
303 %\begin{tcblisting}{title={Back view}}
304 %\bug[back]
305 %\end{tcblisting}
306 %
307 %The key \saminline|3D| will make the bug 3-dimensional:
308 %\begin{tcblisting}{title={3D view}}
309 %\bug[3D]
310 %\end{tcblisting}
311 %
312 %And finally the \saminline|contour| key will only draw the outlines:
313 %\begin{tcblisting}{title={Contours}}
314 %\bug[contour=black]
315 %\end{tcblisting}