Debian Codegraph @

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

raw
1 % !TeX root = ./examples/marmot.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-marmots}[2025/12/11 version v2.5 Drawing marmots in TikZ]
16
17 \RequirePackage{tikz}
18 \RequirePackage{tikzlings-addons}
19 \usetikzlibrary{shadows.blur}
20 \usetikzlibrary{fadings}
21
22 \tikzfading[name=marmot@blush,inner color=transparent!50,outer color=transparent!100]
23
24 \ExplSyntaxOn
25 \ifdefined\sys_rand_seed:
26 \pgfmathsetseed{\sys_rand_seed:}
27 \else
28 \ifdefined\pdfrandomseed % pdflatex
29 \else
30 \ifdefined\randomseed
31 \let\pdfrandomseed\randomseed % post TL19 xelatex and lualatex
32 \else
33 \let\pdfrandomseed\time % pre TL19 xelatex
34 \fi
35 \fi
36 \pgfmathsetseed{\number\pdfrandomseed}
37 \fi
38 \ExplSyntaxOff
39
40 \newcommand*{\marmot}[1][]{%
41 \begin{scope}%
42 \tikzset{/marmot/.cd,#1}%
43 \marmot@draw%
44 \end{scope}%
45 \thing[#1]%
46 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47 \UseHook{tikzlings/marmot/foreground}
48 \UseHook{tikzlings/foreground}
49 \csname marmothookforeground\endcsname
50 \csname tikzlinghookforeground\endcsname
51 %
52 }
53
54 \newif\ifmarmot@blush
55 \newif\ifmarmot@whiskers
56 \newif\ifmarmot@teeth
57 \newif\ifmarmot@threeD
58 \newif\ifmarmot@shadow
59 \newif\ifmarmot@askphil
60 \newif\ifmarmot@leftstep
61 \newif\ifmarmot@rightstep
62 \newif\ifmarmot@back
63 \newif\ifmarmot@contour
64 \newif\ifmarmot@openmouth
65
66 \NewHook{tikzlings/marmot/background}
67 \NewHook{tikzlings/marmot/belly}
68 \NewHook{tikzlings/marmot/body}
69 \NewHook{tikzlings/marmot/foreground}
70
71 \tikzset{
72 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 %
74 % Pass unknown keys on to tikz
75 %
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 /marmot/.search also={/tikz,/pgf,/thing},
78 /marmot/.cd,
79 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80 %
81 % body
82 %
83 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84 body/.store in = \marmot@body,
85 body = brown,
86 eyes/.store in = \marmot@eyes,
87 eyes = \marmot@body!50!black,
88 eye/.forward to = /marmot/eyes,
89 mouth/.store in = \marmot@mouth,
90 mouth = \marmot@body!50!black,
91 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92 %
93 % options
94 %
95 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 blush/.code = \marmot@blushtrue
97 \def\marmot@blushcolor{#1},
98 blush/.default = red,
99 whiskers/.code = \marmot@whiskerstrue
100 \def\marmot@whiskers{#1},
101 whiskers/.default = gray,
102 whisker/.forward to = /marmot/whiskers,
103 teeth/.code = \marmot@teethtrue
104 \def\marmot@teeth{#1},
105 teeth/.default = white,
106 tooth/.forward to = /marmot/teeth,
107 openmouth/.code = \marmot@openmouthtrue,
108 open mouth/.forward to = /marmot/openmouth,
109 3D/.code = \marmot@threeDtrue,
110 shadow/.code = \marmot@shadowtrue,
111 askphil/.code = \marmot@askphiltrue,
112 ask phil/.forward to = /marmot/askphil,
113 leftstep/.code = \marmot@leftsteptrue,
114 left step/.forward to = /marmot/leftstep,
115 rightstep/.code = \marmot@rightsteptrue,
116 right step/.forward to = /marmot/rightstep,
117 back/.code = \marmot@backtrue,
118 contour/.code = \marmot@contourtrue
119 \def\marmot@contour{#1}
120 \def\marmot@blushcolor{#1}
121 \def\marmot@mouth{#1},
122 contour/.default = black,
123 outline/.forward to = /marmot/contour,
124 }
125
126 \def\marmot@draw{%
127 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128 %
129 % minimal bounding box size
130 %
131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
132 \path (-0.625,0.1) rectangle (0.905, 2.17);
133 %
134 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135 %
136 % store the current scale factor
137 % from https://github.com/samcarter/tikzlings/issues/3#issuecomment-461373494
138 %
139 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
140 \pgfgettransformentries{\tmpscaleA}{\tmpscaleB}{\tmpscaleC}{\tmpscaleD}{\tmp}{\tmp}%
141 \pgfmathsetmacro{\scalingfactor}{sqrt(abs(\tmpscaleA*\tmpscaleD-\tmpscaleB*\tmpscaleC))*sqrt(abs((\pgf@xx/1cm)*(\pgf@yy/1cm)-(\pgf@xy/1cm)*(\pgf@yx/1cm)))}%
142 \pgfmathsetmacro{\xscalefactor}{\tmpscaleA}
143 \pgfmathsetmacro{\yscalefactor}{\tmpscaleD}
144 %
145 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146 %
147 % switch between 2D, 3D and contours, from
148 % https://chat.stackexchange.com/transcript/message/45991801#45991801
149 %
150 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
151 \ifmarmot@threeD
152 \def\marmot@part@draw[##1]{\shade[ball color=##1]}
153 \else% 3D
154 \ifmarmot@contour
155 \def\marmot@part@draw[##1]{\draw[##1,\marmot@contour,fill=white,line width=\scalingfactor*0.4pt]}
156 \else% contour
157 \def\marmot@part@draw[##1]{\fill[##1]}
158 \fi% contour
159 \fi% 3D
160 %
161 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
162 %
163 % shadow
164 %
165 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
166 %
167 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
168 \UseHook{tikzlings/marmot/background}
169 \UseHook{tikzlings/background}
170 \csname marmothookbackground\endcsname
171 \csname tikzlinghookbackground\endcsname
172 %
173 \ifmarmot@askphil
174 \pgfmathparse{int(random(1,120))}
175 \let\marmot@random=\pgfmathresult
176 \ifnum\marmot@random>17
177 \marmot@shadowtrue
178 \fi
179 \fi% askphil
180 %
181 \ifmarmot@shadow
182 \fill[opacity=0,blur shadow,] (0.3,0.5) ellipse[x radius=0.28, y radius=0.8, rotate=-80];
183 \fi% shadow
184 %
185 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
186 %
187 % Body parts
188 %
189 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
190 %
191 % Feet %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
192 \ifmarmot@leftstep
193 \marmot@part@draw[\marmot@body!50!black] (-0.255,0.25) ellipse[x radius=0.23, y radius=0.09];
194 \else% step
195 \marmot@part@draw[\marmot@body!50!black] (-0.255,0.2) ellipse[x radius=0.23, y radius=0.09];
196 \fi% step
197 %
198 \ifmarmot@rightstep
199 \marmot@part@draw[\marmot@body!50!black] (0.255,0.25) ellipse[x radius=0.23, y radius=0.09];
200 \else% step
201 \marmot@part@draw[\marmot@body!50!black] (0.255,0.2) ellipse[x radius=0.23, y radius=0.09];
202 \fi% step
203 %
204 % Ears %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
205 \marmot@part@draw[\marmot@body!50!black] (0.255,2.03) ellipse[x radius=0.09, y radius=0.13];
206 \marmot@part@draw[\marmot@body!50!black] (-0.255,2.03) ellipse[x radius=0.09, y radius=0.13];
207 %
208 % Tail %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
209 \unless\ifmarmot@back
210 \marmot@part@draw[\marmot@body!50!black] (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);
211 \fi% back
212 %
213 % Body %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
214 \marmot@part@draw[\marmot@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;
215 %
216 % Tail if back %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
217 \ifmarmot@back
218 \marmot@part@draw[\marmot@body!50!black] (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);
219 \fi% back
220 %
221 % Belly %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
222 \unless\ifmarmot@back
223 \marmot@part@draw[\marmot@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;
224 \fi% back
225 %
226 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
227 \UseHook{tikzlings/marmot/belly}
228 \UseHook{tikzlings/belly}
229 \csname marmothookbelly\endcsname
230 \csname tikzlinghookbelly\endcsname
231 %
232 % Show details only from the front %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
233 \unless\ifmarmot@back
234 %
235 % Arms %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
236 \marmot@part@draw[\marmot@body!50!black] (0.385,0.93) ellipse[x radius=0.24, y radius=0.13, rotate=70];
237 \marmot@part@draw[\marmot@body!50!black] (-0.385,0.93) ellipse[x radius=0.24, y radius=0.13, rotate=-70];
238 %
239 % Muzzle %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
240 \marmot@part@draw[\marmot@body!50!white] (0,1.47) ellipse[x radius=0.23, y radius=0.13];
241 %
242 % Nose %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
243 \marmot@part@draw[\marmot@body!50!black] (0,1.6) circle[radius=0.08];
244 %
245 % Eyes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
246 \marmot@part@draw[\marmot@eyes] (-0.155,1.77) circle[radius=0.05];
247 \marmot@part@draw[\marmot@eyes] (0.155,1.77) circle[radius=0.05];
248 %
249 % Mouth %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
250 \ifmarmot@openmouth
251 \filldraw[\marmot@mouth, line width=\scalingfactor*0.4pt] (0.145,1.51) arc [start angle=-20, end angle=-160, radius=0.155] (-0.145,1.51) arc [start angle=-120, end angle=-60, radius=0.29];
252 \else
253 \draw[\marmot@mouth, line width=\scalingfactor*0.4pt] (0.145,1.51) arc [start angle=-20, end angle=-160, radius=0.16];
254 \fi
255 %
256 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
257 %
258 % optional
259 %
260 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
261 %
262 % Blushed %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
263 \ifmarmot@blush
264 \fill[\marmot@blushcolor,path fading=marmot@blush] (-0.295,1.6) circle[radius=0.1];
265 \fill[\marmot@blushcolor,path fading=marmot@blush] (0.295,1.6) circle[radius=0.1];
266 \fi% blush
267 %
268 % Wiskers %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
269 \ifmarmot@whiskers
270 \fill[\marmot@whiskers] (0.0788, 1.6146) .. controls (0.1658, 1.6299) and (0.2086, 1.5639) .. (0.2956, 1.5486) -- (0.2956, 1.5586) .. controls (0.2097, 1.5737) and (0.1648, 1.6297) .. (0.0788, 1.6146) -- cycle;
271 \fill[\marmot@whiskers] (-0.0788, 1.6146) .. controls (-0.1658, 1.6299) and (-0.2087, 1.5639) .. (-0.2956, 1.5486) -- (-0.2956, 1.5586) .. controls (-0.2097, 1.5737) and (-0.1648, 1.6297) .. (-0.0788, 1.6146) -- cycle;
272 \fill[\marmot@whiskers] (0.0752, 1.6281) .. controls (0.1583, 1.6583) and (0.2171, 1.6309) .. (0.3002, 1.6007) -- (0.3002, 1.6107) .. controls (0.2174, 1.6408) and (0.158, 1.6582) .. (0.0752, 1.6281) -- cycle;
273 \fill[\marmot@whiskers] (-0.0752, 1.6281) .. controls (-0.1583, 1.6583) and (-0.2171, 1.6309) .. (-0.3002, 1.6007) -- (-0.3002, 1.6107) .. controls (-0.2174, 1.6408) and (-0.158, 1.6582) .. (-0.0752, 1.6281) -- cycle;
274 \fill[\marmot@whiskers] (0.0671, 1.6443) .. controls (0.1414, 1.6925) and (0.2182, 1.7164) .. (0.2925, 1.6682) -- (0.2925, 1.6782) .. controls (0.2179, 1.7266) and (0.1417, 1.6927) .. (0.0671, 1.6443) -- cycle;
275 \fill[\marmot@whiskers] (-0.0671, 1.6443) .. controls (-0.1414, 1.6925) and (-0.2182, 1.7164) .. (-0.2925, 1.6682) -- (-0.2925, 1.6782) .. controls (-0.2179, 1.7266) and (-0.1417, 1.6927) .. (-0.0671, 1.6443) -- cycle;
276 \fi% whiskers
277 %
278 % Teeth %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
279 \ifmarmot@teeth
280 \fill[\marmot@body!50!black] (0.048,1.413) rectangle (-0.048,1.373);
281 \fill[\marmot@teeth] (-0.045,1.407) rectangle (-0.004,1.376);
282 \fill[\marmot@teeth] (0.045,1.407) rectangle (0.004,1.376);
283 \fi% teeth
284 %
285 \fi% back
286 %
287 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
288 \UseHook{tikzlings/marmot/body}
289 \UseHook{tikzlings/body}
290 \csname marmothookbody\endcsname
291 \csname tikzlinghookbody\endcsname
292 %
293 }
294
295 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
296 %%
297 %% Documentation
298 %%
299 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
300 %\clearpage
301 %\section[Marmot]{Phil, the marmot}
302 %
303 %\emph{Phil got his name from Punxsutawney Phil, the famous weather forecasting groundhog}
304 %
305 %\subsection{Package name}
306 %
307 %\begin{tcolorbox}[title={Package usage}]
308 %\begin{samcode}
309 %\usepackage{tikzlings-marmots}
310 %\end{samcode}
311 %\end{tcolorbox}
312 %
313 %\subsection{Basic Usage}
314 %
315 %\begin{tcblisting}{title={Basic marmot}}
316 %\marmot
317 %\end{tcblisting}
318 %
319 %\subsection{Options}
320 %
321 %The basic marmot can be modified by changing its colour:
322 %\begin{tcblisting}{title={Body colour}}
323 %\marmot[body=blue]
324 %\end{tcblisting}
325 %
326 %In addition to the colour of the body, the colour of various body parts can be adjusted:
327 %\begin{tcblisting}{title={Eye colour}}
328 %\marmot[eyes=red]
329 %\end{tcblisting}
330 %\begin{tcblisting}{title={Mouth colour}}
331 %\marmot[mouth=red]
332 %\end{tcblisting}
333 %
334 % The marmot can open its mouth:
335 %\begin{tcblisting}{title={Open mouth}}
336 %\marmot[openmouth]
337 %\end{tcblisting}
338 %
339 %The marmot can also blush
340 %\begin{tcblisting}{title={Blushing marmot}}
341 %\marmot[blush=red]
342 %\end{tcblisting}
343 %
344 %and whiskers can be added:
345 %\begin{tcblisting}{title={Whiskers colour}}
346 %\marmot[whiskers=gray]
347 %\end{tcblisting}
348 %
349 %Some marmots even show their chisel teeth:
350 %\begin{tcblisting}{title={Teeth colour}}
351 %\marmot[teeth=white]
352 %\end{tcblisting}
353 %
354 %or can cast a shadow:
355 %\begin{tcblisting}{title={Shadow}}
356 %\marmot[shadow]
357 %\end{tcblisting}
358 %
359 %This ability is important if you want to ask Punxsutawney Phil\footnote{\url{https://en.wikipedia.org/wiki/Punxsutawney_Phil}} on Groundhog Day how the weather is going to be. With a probability derived from the statistics of 120 Groundhog Days\footnote{\hbadness=99999\url{https://www.livescience.com/32974-punxsutawney-phil-weather-prediction-accuracy.html}} the option \saminline|askphil| might or might not result in a shadow.
360 %\begin{tcblisting}{title={Ask Phil}}
361 %\marmot[askphil]
362 %\end{tcblisting}
363 %
364 %If a good weather prognosis is derived, the happy marmot can dance by lifting up its left and right foot:
365 %\begin{tcblisting}{title={Walking}}
366 %\marmot[leftstep]
367 %\marmot[rightstep,xshift=2cm]
368 %\end{tcblisting}
369 %
370 %To view the marmot from behind:
371 %\begin{tcblisting}{title={Back view}}
372 %\marmot[back]
373 %\end{tcblisting}
374 %
375 %The key \saminline|3D| will make the marmot 3-dimensional:
376 %\begin{tcblisting}{title={3D view}}
377 %\marmot[3D]
378 %\end{tcblisting}
379 %
380 %And finally the \saminline|contour| key will only draw the outlines:
381 %\begin{tcblisting}{title={Contours}}
382 %\marmot[contour=black]
383 %\end{tcblisting}