Debian Codegraph @

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

raw
1 % !TeX root = ./examples/snowman.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-snowmen}[2025/12/11 version v2.5 Draw snowmen in TikZ]
16
17 \RequirePackage{tikz}
18 \RequirePackage{tikzlings-addons}
19
20 \newcommand*{\snowman}[1][]{%
21 \begin{scope}%
22 \tikzset{/snowman/.cd,#1}%
23 \ifsnowman@globalwarming
24 \snowman@drawpuddle%
25 \else
26 \snowman@draw%
27 \fi
28 \end{scope}%
29 \thing[#1]%
30 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 \UseHook{tikzlings/snowman/foreground}
32 \UseHook{tikzlings/foreground}
33 \csname snowmanhookforeground\endcsname
34 \csname tikzlinghookforeground\endcsname
35 %
36 }
37
38 \newif\ifsnowman@threeD
39 \newif\ifsnowman@back
40 \newif\ifsnowman@globalwarming
41 \newif\ifsnowman@contour
42 \newif\ifsnowman@openmouth
43
44 \NewHook{tikzlings/snowman/background}
45 \NewHook{tikzlings/snowman/belly}
46 \NewHook{tikzlings/snowman/body}
47 \NewHook{tikzlings/snowman/foreground}
48
49 \tikzset{
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 %
52 % Pass unknown keys on to tikz
53 %
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 /snowman/.search also={/tikz,/pgf,/thing},
56 /snowman/.cd,
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 %
59 % body
60 %
61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62 body/.store in = \snowman@body,
63 body = white!95!black,
64 eyes/.store in = \snowman@eyes,
65 eyes = black,
66 eye/.forward to = /snowman/eyes,
67 nose/.store in = \snowman@nose,
68 nose = orange,
69 mouth/.store in = \snowman@mouth,
70 mouth = black,
71 buttons/.store in = \snowman@buttons,
72 buttons = black,
73 button/.forward to = /snowman/buttons,
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75 %
76 % options
77 %
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79 openmouth/.code = \snowman@openmouthtrue,
80 open mouth/.forward to = /snowman/openmouth,
81 3D/.code = \snowman@threeDtrue,
82 back/.code = \snowman@backtrue,
83 globalwarming/.code= \snowman@globalwarmingtrue
84 \def\snowman@globalwarming{#1},
85 globalwarming/.default = blue!10!white,
86 global warming/.forward to = /snowman/globalwarming,
87 contour/.code = \snowman@contourtrue
88 \def\snowman@contour{#1}
89 \def\snowman@mouth{#1},
90 contour/.default = black,
91 outline/.forward to = /snowman/contour,
92 }
93
94 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95 %%
96 %% normal snowman
97 %%
98 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99 \def\snowman@draw{%
100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101 %
102 % minimal bounding box size
103 %
104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105 \path (-0.75, 0.0) rectangle (0.75, 2.13);
106 %
107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108 %
109 % store the current scale factor
110 % from https://github.com/samcarter/tikzlings/issues/3#issuecomment-461373494
111 %
112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113 \pgfgettransformentries{\tmpscaleA}{\tmpscaleB}{\tmpscaleC}{\tmpscaleD}{\tmp}{\tmp}%
114 \pgfmathsetmacro{\scalingfactor}{sqrt(abs(\tmpscaleA*\tmpscaleD-\tmpscaleB*\tmpscaleC))*sqrt(abs((\pgf@xx/1cm)*(\pgf@yy/1cm)-(\pgf@xy/1cm)*(\pgf@yx/1cm)))}%
115 \pgfmathsetmacro{\xscalefactor}{\tmpscaleA}
116 \pgfmathsetmacro{\yscalefactor}{\tmpscaleD}
117 %
118 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
119 %
120 % switch between 2D, 3D and contours, from
121 % https://chat.stackexchange.com/transcript/message/45991801#45991801
122 %
123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124 \ifsnowman@threeD
125 \def\snowman@part@draw[##1]{\shade[ball color=##1]}
126 \else% 3D
127 \ifsnowman@contour
128 \def\snowman@part@draw[##1]{\draw[##1,\snowman@contour,fill=white,line width=\scalingfactor*0.4pt]}
129 \else% contour
130 \def\snowman@part@draw[##1]{\fill[##1]}
131 \fi% contour
132 \fi% 3D
133 %
134 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135 %
136 % Body parts
137 %
138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139 %
140 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141 \UseHook{tikzlings/snowman/background}
142 \UseHook{tikzlings/background}
143 \csname snowmanhookbackground\endcsname
144 \csname tikzlinghookbackground\endcsname
145 %
146 % Arms %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
147 \snowman@part@draw[\snowman@body] (0.5,1.1) ellipse[x radius=0.3, y radius=0.12, rotate=-50];
148 \snowman@part@draw[\snowman@body] (-0.5,1.1) ellipse[x radius=0.3, y radius=0.12, rotate=50];
149 %
150 % Body + Head %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
151 \snowman@part@draw[\snowman@body] (0,0.5) ellipse[x radius=0.6, y radius=0.5];
152 \snowman@part@draw[\snowman@body] (0,1.1) ellipse[x radius=0.5, y radius=0.4];
153 \snowman@part@draw[\snowman@body] (0,1.7) circle[radius=0.4];
154 %
155 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
156 \UseHook{tikzlings/snowman/belly}
157 \UseHook{tikzlings/belly}
158 \csname snowmanhookbelly\endcsname
159 \csname tikzlinghookbelly\endcsname
160 %
161 % Show details only from the front %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
162 \unless\ifsnowman@back
163 %
164 % Mouth% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
165 \fill[\snowman@mouth] (0,1.5) circle[radius=0.016];
166 \fill[\snowman@mouth] (0.04,1.507) circle[radius=0.016];
167 \fill[\snowman@mouth] (-0.04,1.507) circle[radius=0.016];
168 \fill[\snowman@mouth] (0.08,1.522) circle[radius=0.016];
169 \fill[\snowman@mouth] (-0.08,1.522) circle[radius=0.016];
170 \fill[\snowman@mouth] (0.12,1.543) circle[radius=0.016];
171 \fill[\snowman@mouth] (-0.12,1.543) circle[radius=0.016];
172 \ifsnowman@openmouth
173 \fill[\snowman@mouth] (0,1.57) circle[radius=0.016];
174 \fill[\snowman@mouth] (-0.04,1.565) circle[radius=0.016];
175 \fill[\snowman@mouth] (-0.08,1.56) circle[radius=0.016];
176 \fill[\snowman@mouth] (0.04,1.565) circle[radius=0.016];
177 \fill[\snowman@mouth] (0.08,1.56) circle[radius=0.016];
178 \fi
179 %
180 % Eyes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181 \snowman@part@draw[\snowman@eyes] (-0.155,1.8) circle[radius=0.04];
182 \snowman@part@draw[\snowman@eyes] (0.155,1.8) circle[radius=0.04];
183 %
184 % Nose %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
185 \snowman@part@draw[\snowman@nose] (0,1.72) arc [radius=0.05, start angle=90, end angle=270] (0,1.62) -- (0.15,1.64) -- (0,1.72);
186 %
187 % Buttons %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
188 \snowman@part@draw[\snowman@buttons] (0,1.15) circle[radius=0.04];
189 \snowman@part@draw[\snowman@buttons] (0,0.95) circle[radius=0.04];
190 \snowman@part@draw[\snowman@buttons] (0,0.75) circle[radius=0.04];
191 %
192 \fi% back
193 %
194 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
195 \UseHook{tikzlings/snowman/body}
196 \UseHook{tikzlings/body}
197 \csname snowmanhookbody\endcsname
198 \csname tikzlinghookbody\endcsname
199 %
200 }
201
202 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203 %%
204 %% molten snowman
205 %%
206 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
207
208 \def\snowman@drawpuddle{
209 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
210 %
211 % minimal bounding box size
212 %
213 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
214 \path (-0.75, 0.0) rectangle (0.75, 2.13);
215 %
216 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
217 %
218 % store the current scale factor
219 % from https://github.com/samcarter/tikzlings/issues/3#issuecomment-461373494
220 %
221 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
222 \pgfgettransformentries{\tmpscaleA}{\tmpscaleB}{\tmpscaleC}{\tmpscaleD}{\tmp}{\tmp}%
223 \pgfmathsetmacro{\scalingfactor}{sqrt(abs(\tmpscaleA*\tmpscaleD-\tmpscaleB*\tmpscaleC))*sqrt(abs((\pgf@xx/1cm)*(\pgf@yy/1cm)-(\pgf@xy/1cm)*(\pgf@yx/1cm)))}%
224 \pgfmathsetmacro{\xscalefactor}{\tmpscaleA}
225 \pgfmathsetmacro{\yscalefactor}{\tmpscaleD}
226 %
227 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
228 %
229 % switch between 2D, 3D and contours, from
230 % https://chat.stackexchange.com/transcript/message/45991801#45991801
231 %
232 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
233 \ifsnowman@threeD
234 \def\snowman@part@draw[##1]{\shade[ball color=##1]}
235 \else% 3D
236 \ifsnowman@contour
237 \def\snowman@part@draw[##1]{\draw[##1,\snowman@contour,fill=white,line width=\scalingfactor*0.4pt]}
238 \else% contour
239 \def\snowman@part@draw[##1]{\fill[##1]}
240 \fi% contour
241 \fi% 3D
242 %
243 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
244 %
245 % Body parts
246 %
247 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
248 %
249 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
250 \UseHook{tikzlings/snowman/background}
251 \UseHook{tikzlings/background}
252 \csname snowmanhookbackground\endcsname
253 \csname tikzlinghookbackground\endcsname
254 %
255 % Puddle %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
256 \ifsnowman@contour
257 \draw[\snowman@contour,fill=white,line width=\scalingfactor*0.4pt] (0,1.15) ellipse[x radius=1.6,y radius=1.15];
258 \else% contour
259 \fill[\snowman@globalwarming] (0,1.15) ellipse[x radius=1.6,y radius=1.15];
260 \fi% contour
261 %
262 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
263 \UseHook{tikzlings/snowman/belly}
264 \UseHook{tikzlings/belly}
265 \csname snowmanhookbelly\endcsname
266 \csname tikzlinghookbelly\endcsname
267 %
268 % Mouth %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
269 \fill[\snowman@mouth] (0,1.23) circle[radius=0.025];
270 \fill[\snowman@mouth] (0.06,1.3) circle[radius=0.025];
271 \fill[\snowman@mouth] (-0.06,1.27) circle[radius=0.025];
272 \fill[\snowman@mouth] (0.09,1.37) circle[radius=0.025];
273 \fill[\snowman@mouth] (-0.18,1.28) circle[radius=0.025];
274 \fill[\snowman@mouth] (0.2,1.28) circle[radius=0.025];
275 \fill[\snowman@mouth] (-0.25,1.2) circle[radius=0.025];
276 %
277 % Eyes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
278 \snowman@part@draw[\snowman@eyes] (-0.5,1.75) circle[radius=0.06];
279 \snowman@part@draw[\snowman@eyes] (-0.1,1.55) circle[radius=0.06];
280 %
281 % Nose %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
282 \snowman@part@draw[\snowman@nose] (-0.6,1.4) -- (-0.8,1.42) -- (-0.6,1.54) (-0.6,1.4) arc[radius=0.07, start angle=-90, end angle=90];
283 %
284 % Buttons %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
285 \snowman@part@draw[\snowman@buttons] (0.1,0.8) circle[radius=0.06];
286 \snowman@part@draw[\snowman@buttons] (-0.15,0.55) circle[radius=0.06];
287 \snowman@part@draw[\snowman@buttons] (0,0.25) circle[radius=0.06];
288 %
289 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
290 \UseHook{tikzlings/snowman/body}
291 \UseHook{tikzlings/body}
292 \csname snowmanhookbody\endcsname
293 \csname tikzlinghookbody\endcsname
294 %
295 }
296
297 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
298 %%
299 %% Documentation
300 %%
301 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
302 %\clearpage
303 %\section[Snowman]{Yuki, the snowman}
304 %
305 %\emph{Yuki is the transcription of the Japanese word for snow}
306 %
307 %\subsection{Package name}
308 %
309 %\begin{tcolorbox}[title={Package usage}]
310 %\begin{samcode}
311 %\usepackage{tikzlings-snowmen}
312 %\end{samcode}
313 %\end{tcolorbox}
314 %
315 %\subsection{Basic Usage}
316 %
317 %\begin{tcblisting}{title={Basic snowman}}
318 %\snowman
319 %\end{tcblisting}
320 %
321 %\subsection{Options}
322 %
323 %The basic snowman can be modified by changing its colour:
324 %\begin{tcblisting}{title={Body colour}}
325 %\snowman[body=blue]
326 %\end{tcblisting}
327 %
328 %In addition to the colour of the body, the colour of various body parts can be adjusted:
329 %\begin{tcblisting}{title={Eye colour}}
330 %\snowman[eyes=red]
331 %\end{tcblisting}
332 %\begin{tcblisting}{title={Nose colour}}
333 %\snowman[nose=red]
334 %\end{tcblisting}
335 %\begin{tcblisting}{title={Mouth colour}}
336 %\snowman[mouth=red]
337 %\end{tcblisting}
338 %\begin{tcblisting}{title={Button colour}}
339 %\snowman[buttons=red]
340 %\end{tcblisting}
341 %
342 % The snowman can open its mouth:
343 %\begin{tcblisting}{title={Open mouth}}
344 %\snowman[openmouth]
345 %\end{tcblisting}
346 %
347 %The biggest enemy of the snowman are raising temperatures:
348 %\begin{tcblisting}{title={Global warming}}
349 %\snowman[globalwarming,tophat]
350 %\end{tcblisting}
351 %
352 %To view the snowman from behind:
353 %\begin{tcblisting}{title={Back view}}
354 %\snowman[back]
355 %\end{tcblisting}
356 %
357 %The key \saminline|3D| will make the snowman 3-dimensional:
358 %\begin{tcblisting}{title={3D view}}
359 %\snowman[3D]
360 %\end{tcblisting}
361 %
362 %And finally the \saminline|contour| key will only draw the outlines:
363 %\begin{tcblisting}{title={Contours}}
364 %\snowman[contour=black]
365 %\end{tcblisting}