Debian Codegraph @

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

raw
1 % !TeX root = ./examples/moles.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-moles}[2025/12/11 version v2.5 Drawing moles in TikZ]
16
17 \RequirePackage{tikz}
18 \RequirePackage{tikzlings-addons}
19
20 \newcommand*{\moles}[1][]{%
21 \begin{scope}%
22 \tikzset{/moles/.cd,#1}%
23 \moles@draw%
24 \end{scope}%
25 \thing[#1]%
26 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27 \UseHook{tikzlings/moles/foreground}
28 \UseHook{tikzlings/foreground}
29 \csname moleshookforeground\endcsname
30 \csname tikzlinghookforeground\endcsname
31 %
32 }
33
34 \newif\ifmoles@threeD
35 \newif\ifmoles@leftstep
36 \newif\ifmoles@rightstep
37 \newif\ifmoles@back
38 \newif\ifmoles@contour
39 \newif\ifmoles@openmouth
40
41 \NewHook{tikzlings/moles/background}
42 \NewHook{tikzlings/moles/belly}
43 \NewHook{tikzlings/moles/body}
44 \NewHook{tikzlings/moles/foreground}
45
46 \tikzset{
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48 %
49 % Pass unknown keys on to tikz
50 %
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 /moles/.search also={/tikz,/pgf,/thing},
53 /moles/.cd,
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 %
56 % body
57 %
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59 body/.store in = \moles@body,
60 body = gray,
61 eyes/.store in = \moles@eyes,
62 eyes = \moles@body!60!black,
63 eye/.forward to = /moles/eyes,
64 feet/.store in = \moles@feet,
65 feet = red!20!white!50!brown,
66 foot/.forward to = /moles/feet,
67 hands/.store in = \moles@hands,
68 hands = red!20!white!50!brown,
69 hand/.forward to = /moles/hands,
70 muzzle/.store in = \moles@muzzle,
71 muzzle = red!20!white!50!brown,
72 mouth/.store in = \moles@mouth,
73 mouth = \moles@body!60!black,
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75 %
76 % options
77 %
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79 openmouth/.code = \moles@openmouthtrue,
80 open mouth/.forward to = /moles/openmouth,
81 3D/.code = \moles@threeDtrue,
82 leftstep/.code = \moles@leftsteptrue,
83 left step/.forward to = /moles/leftstep,
84 rightstep/.code = \moles@rightsteptrue,
85 right step/.forward to = /moles/rightstep,
86 back/.code = \moles@backtrue,
87 contour/.code = \moles@contourtrue
88 \def\moles@contour{#1}
89 \def\moles@mouth{#1}
90 \def\moles@eyes{#1},
91 contour/.default = black,
92 outline/.forward to = /moles/contour,
93 }
94
95 \def\moles@draw{%
96 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97 %
98 % minimal bounding box size
99 %
100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101 \path (-0.625,0.1) rectangle (0.905, 2.17);
102 %
103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104 %
105 % store the current scale factor
106 % from https://github.com/samcarter/tikzlings/issues/3#issuecomment-461373494
107 %
108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109 \pgfgettransformentries{\tmpscaleA}{\tmpscaleB}{\tmpscaleC}{\tmpscaleD}{\tmp}{\tmp}%
110 \pgfmathsetmacro{\scalingfactor}{sqrt(abs(\tmpscaleA*\tmpscaleD-\tmpscaleB*\tmpscaleC))*sqrt(abs((\pgf@xx/1cm)*(\pgf@yy/1cm)-(\pgf@xy/1cm)*(\pgf@yx/1cm)))}%
111 \pgfmathsetmacro{\xscalefactor}{\tmpscaleA}
112 \pgfmathsetmacro{\yscalefactor}{\tmpscaleD}
113 %
114 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115 %
116 % switch between 2D, 3D and contours, from
117 % https://chat.stackexchange.com/transcript/message/45991801#45991801
118 %
119 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120 \ifmoles@threeD
121 \def\moles@part@draw[##1]{\shade[ball color=##1]}
122 \else% 3D
123 \ifmoles@contour
124 \def\moles@part@draw[##1]{\draw[##1,\moles@contour,fill=white,line width=\scalingfactor*0.4pt]}
125 \else% contour
126 \def\moles@part@draw[##1]{\fill[##1]}
127 \fi% contour
128 \fi% 3D
129 %
130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 %
132 % Body parts
133 %
134 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135 %
136 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
137 \UseHook{tikzlings/moles/background}
138 \UseHook{tikzlings/background}
139 \csname moleshookbackground\endcsname
140 \csname tikzlinghookbackground\endcsname
141 %
142 % Feet %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
143 \ifmoles@leftstep
144 \moles@part@draw[\moles@feet] (-0.255,0.25) ellipse[x radius=0.23, y radius=0.09];
145 \else% step
146 \moles@part@draw[\moles@feet] (-0.255,0.2) ellipse[x radius=0.23, y radius=0.09];
147 \fi% step
148 \ifmoles@rightstep
149 \moles@part@draw[\moles@feet] (0.255,0.25) ellipse[x radius=0.23, y radius=0.09];
150 \else% step
151 \moles@part@draw[\moles@feet] (0.255,0.2) ellipse[x radius=0.23, y radius=0.09];
152 \fi% step
153 %
154 % Tail %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
155 \unless\ifmoles@back
156 \moles@part@draw[\moles@body] (0.8856, 0.6504) .. controls (0.8656, 0.3803) and (0.0267, 0.2202) .. (0.0167, 0.4203) .. controls (-0.0033, 0.5404) and (0.1104, 0.4397) .. (0.3951, 0.4803) .. controls (0.6557, 0.5175) and (0.8856, 0.7005) .. (0.8856, 0.6504);
157 \fi% back
158 %
159 % Hair %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
160 \moles@part@draw[\moles@body] (-0.09, 2.06) .. controls (-0.09, 2.06) and (-0.13, 2.25) .. (-0.07, 2.27) .. controls (-0.09, 2.13) and (0.04, 2.08) .. (0.04, 2.08) .. controls (0.04, 2.08) and (0.02, 2.20) .. (0.06, 2.21) .. controls (0.06, 2.11) and (0.13, 2.08) .. (0.13, 2.08) -- cycle;
161 %
162 % Body %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
163 \moles@part@draw[\moles@body] (0.595, 0.92) .. controls (0.595, 0.26) and (0.355, 0.18) .. (0, 0.18) .. controls (-0.355, 0.18) and (-0.595, 0.26) .. (-0.595, 0.92) .. controls (-0.605, 1.58) and (-0.335, 2.11) .. (0, 2.11) .. controls (0.335, 2.11) and (0.605, 1.58) .. (0.595, 0.92) -- cycle;
164 %
165 % Tail if back %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
166 \ifmoles@back
167 \moles@part@draw[\moles@body] (0.8856, 0.6504) .. controls (0.8656, 0.3803) and (0.0267, 0.2202) .. (0.0167, 0.4203) .. controls (-0.0033, 0.5404) and (0.1104, 0.4397) .. (0.3951, 0.4803) .. controls (0.6557, 0.5175) and (0.8856, 0.7005) .. (0.8856, 0.6504) -- cycle;
168 \fi% back
169 %
170 % Belly %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
171 \unless\ifmoles@back
172 \moles@part@draw[\moles@body!50!white] (0.425, 0.71) .. controls (0.425, 0.41) and (0.245, 0.37) .. (0, 0.37) .. controls (-0.245, 0.37) and (-0.425, 0.41) .. (-0.425, 0.71) .. controls (-0.425, 1.01) and (-0.225, 1.26) .. (0, 1.26) .. controls (0.225, 1.26) and (0.425, 1.01) .. (0.425, 0.71) -- cycle;
173 \fi% back
174 %
175 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
176 \UseHook{tikzlings/moles/belly}
177 \UseHook{tikzlings/belly}
178 \csname moleshookbelly\endcsname
179 \csname tikzlinghookbelly\endcsname
180 %
181 % Show details only from the front %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
182 \unless\ifmoles@back
183 %
184 % Arms %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
185 \moles@part@draw[\moles@body] (0.37,0.86) ellipse[x radius=0.27, y radius=0.13, rotate=70];
186 \moles@part@draw[\moles@body] (-0.37,0.86) ellipse[x radius=0.27, y radius=0.13, rotate=-70];
187 %
188 % Hands %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
189 \ifmoles@contour
190 \moles@part@draw[] (-0.37,0.6) -- (-0.32,0.53) -- (-0.3,0.6) -- (-0.23,0.55) -- (-0.23,0.64) -- (-0.16,0.59) -- (-0.18,0.67) -- cycle;
191 \moles@part@draw[] (0.37,0.6) -- (0.32,0.53) -- (0.3,0.6) -- (0.23,0.55) -- (0.23,0.64) -- (0.16,0.59) -- (0.18,0.67) -- cycle;
192 \else% contour
193 \fill[white] (-0.37,0.6) -- (-0.32,0.53) -- (-0.3,0.6) -- (-0.23,0.55) -- (-0.23,0.64) -- (-0.16,0.59) -- (-0.18,0.67) -- cycle;
194 \fill[white] (0.37,0.6) -- (0.32,0.53) -- (0.3,0.6) -- (0.23,0.55) -- (0.23,0.64) -- (0.16,0.59) -- (0.18,0.67) -- cycle;
195 \fi% contour
196 \moles@part@draw[\moles@hands] (0.285,0.65) ellipse[x radius=0.08, y radius=0.13, rotate=70];
197 \moles@part@draw[\moles@hands] (-0.285,0.65) ellipse[x radius=0.08, y radius=0.13, rotate=-70];
198 %
199 % Muzzle %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
200 \moles@part@draw[\moles@muzzle] ( 0.22, 1.46) .. controls ( 0.22, 1.50) and ( 0.22, 1.53) .. ( 0.17, 1.56) .. controls ( 0.11, 1.58) and ( 0.05, 1.66) .. ( 0.00, 1.66) .. controls (-0.05, 1.66) and (-0.11, 1.58) .. (-0.17, 1.56) .. controls (-0.22, 1.53) and (-0.22, 1.50) .. (-0.22, 1.46) .. controls (-0.22, 1.39) and (-0.14, 1.33) .. ( 0.00, 1.33) .. controls ( 0.14, 1.33) and ( 0.22, 1.39) .. ( 0.22, 1.46) -- cycle;
201 %
202 % Nose %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203 \moles@part@draw[\moles@body!60!black] (0,1.67) circle[radius=0.055];
204 %
205 % Eyes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
206 \ifmoles@threeD
207 \fill[\moles@eyes] (-0.165,1.79) ellipse[x radius=0.055, y radius=0.015, rotate=-15];
208 \fill[\moles@eyes!50!black] (0.165,1.79) ellipse[x radius=0.055, y radius=0.015, rotate=15];
209 \else% 3D
210 \fill[\moles@eyes] (-0.165,1.79) ellipse[x radius=0.055, y radius=0.015, rotate=-15];
211 \fill[\moles@eyes] (0.165,1.79) ellipse[x radius=0.055, y radius=0.015, rotate=15];
212 \fi% 3D
213 %
214 % Mouth %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
215 \ifmoles@openmouth
216 \filldraw[\moles@mouth, line width=\scalingfactor*0.4pt] (0.145,1.51) arc [start angle=-20, end angle=-160, radius=0.16] ;
217 \else
218 \draw[\moles@mouth, line width=\scalingfactor*0.4pt] (0.145,1.51) arc [start angle=-20, end angle=-160, radius=0.16];
219 \fi
220 %
221 \fi% back
222 %
223 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
224 \UseHook{tikzlings/moles/body}
225 \UseHook{tikzlings/body}
226 \csname moleshookbody\endcsname
227 \csname tikzlinghookbody\endcsname
228 %
229 }
230
231 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
232 %%
233 %% Documentation
234 %%
235 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
236 %\clearpage
237 %\section[Mole]{Wilhelm, the mole}
238 %
239 %\emph{The mole was added in celebration of the international mole day and is named after the chemist Wilhelm Ostwald}
240 %
241 %\subsection{Package name}
242 %
243 %\begin{tcolorbox}[title={Package usage}]
244 %\begin{samcode}
245 %\usepackage{tikzlings-moles}
246 %\end{samcode}
247 %\end{tcolorbox}
248 %
249 %\subsection{Basic Usage}
250 %
251 %\textcolor{samred}{\textbf{Attention:} In contrast to the other \tikzlings the macro name is the plural form to avoid conflicts with \saminline|siunitx| and similar packages.}
252 %\begin{tcblisting}{title={Basic mole}}
253 %\moles
254 %\end{tcblisting}
255 %
256 %\subsection{Options}
257 %
258 %The basic mole can be modified by changing its colour:
259 %\begin{tcblisting}{title={Body colour}}
260 %\moles[body=blue]
261 %\end{tcblisting}
262 %
263 %In addition to the colour of the body, the colour of various body parts can be adjusted:
264 %\begin{tcblisting}{title={Eye colour}}
265 %\moles[eyes=red]
266 %\end{tcblisting}
267 %\begin{tcblisting}{title={Muzzle colour}}
268 %\moles[muzzle=red]
269 %\end{tcblisting}
270 %\begin{tcblisting}{title={Hand colour}}
271 %\moles[hands=red]
272 %\end{tcblisting}
273 %\begin{tcblisting}{title={Foot colour}}
274 %\moles[feet=red]
275 %\end{tcblisting}
276 %\begin{tcblisting}{title={Mouth colour}}
277 %\moles[mouth=red]
278 %\end{tcblisting}
279 %
280 % The mole can open its mouth:
281 %\begin{tcblisting}{title={Open mouth}}
282 %\moles[openmouth]
283 %\end{tcblisting}
284 %
285 %And the mole can lift its legs:
286 %\begin{tcblisting}{title={Walking}}
287 %\moles[leftstep]
288 %\moles[rightstep,xshift=2cm]
289 %\end{tcblisting}
290 %
291 %To view the mole from behind:
292 %\begin{tcblisting}{title={Back view}}
293 %\moles[back]
294 %\end{tcblisting}
295 %
296 %The key \saminline|3D| will make the mole 3-dimensional:
297 %\begin{tcblisting}{title={3D view}}
298 %\moles[3D]
299 %\end{tcblisting}
300 %
301 %And finally the \saminline|contour| key will only draw the outlines:
302 %\begin{tcblisting}{title={Contours}}
303 %\moles[contour=black]
304 %\end{tcblisting}