Debian Codegraph @

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

raw
1 % !TeX root = ./examples/squirrel.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-squirrels}[2025/12/11 version v2.5 Drawing squirrels in TikZ]
16
17 \RequirePackage{tikz}
18 \RequirePackage{tikzlings-addons}
19
20 \newcommand*{\squirrel}[1][]{%
21 \begin{scope}%
22 \tikzset{/squirrel/.cd,#1}%
23 \squirrel@draw%
24 \end{scope}%
25 \thing[#1]%
26 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27 \UseHook{tikzlings/squirrel/foreground}
28 \UseHook{tikzlings/foreground}
29 \csname squirrelhookforeground\endcsname
30 \csname tikzlinghookforeground\endcsname
31 }
32
33 \newif\ifsquirrel@threeD
34 \newif\ifsquirrel@leftstep
35 \newif\ifsquirrel@rightstep
36 \newif\ifsquirrel@back
37 \newif\ifsquirrel@contour
38 \newif\ifsquirrel@openmouth
39
40 \NewHook{tikzlings/squirrel/background}
41 \NewHook{tikzlings/squirrel/belly}
42 \NewHook{tikzlings/squirrel/body}
43 \NewHook{tikzlings/squirrel/foreground}
44
45 \tikzset{
46 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47 %
48 % Pass unknown keys on to tikz
49 %
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 /squirrel/.search also={/tikz,/pgf,/thing},
52 /squirrel/.cd,
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 %
55 % body
56 %
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 body/.store in = \squirrel@body,
59 body = brown!40!gray!90!red,
60 eyes/.store in = \squirrel@eyes,
61 eyes = white,
62 eye/.forward to = /squirrel/eyes,
63 pupils/.store in = \squirrel@pupils,
64 pupils = black,
65 pupil/.forward to = /squirrel/pupils,
66 mouth/.store in = \squirrel@mouth,
67 mouth = \squirrel@body!70!brown!60!black,
68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69 %
70 % options
71 %
72 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 openmouth/.code = \squirrel@openmouthtrue,
74 open mouth/.forward to = /squirrel/openmouth,
75 3D/.code = \squirrel@threeDtrue
76 \def\squirrel@mouth{\squirrel@body!40!black},
77 leftstep/.code = \squirrel@leftsteptrue,
78 left step/.forward to = /squirrel/leftstep,
79 rightstep/.code = \squirrel@rightsteptrue,
80 right step/.forward to = /squirrel/rightstep,
81 back/.code = \squirrel@backtrue,
82 contour/.code = \squirrel@contourtrue
83 \def\squirrel@contour{#1},
84 contour/.default = black,
85 outline/.forward to = /squirrel/contour,
86 }
87
88 \def\squirrel@draw{%
89 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90 %
91 % minimal bounding box size
92 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
93 \path (-0.53,0.1) rectangle (1.12,2.15);
94 %
95 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 %
97 % store the current scale factor
98 % from https://github.com/samcarter/tikzlings/issues/3#issuecomment-461373494
99 %
100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101 \pgfgettransformentries{\tmpscaleA}{\tmpscaleB}{\tmpscaleC}{\tmpscaleD}{\tmp}{\tmp}%
102 \pgfmathsetmacro{\scalingfactor}{sqrt(abs(\tmpscaleA*\tmpscaleD-\tmpscaleB*\tmpscaleC))*sqrt(abs((\pgf@xx/1cm)*(\pgf@yy/1cm)-(\pgf@xy/1cm)*(\pgf@yx/1cm)))}%
103 \pgfmathsetmacro{\xscalefactor}{\tmpscaleA}
104 \pgfmathsetmacro{\yscalefactor}{\tmpscaleD}
105 %
106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107 %
108 % switch between 2D, 3D and contours, from
109 % https://chat.stackexchange.com/transcript/message/45991801#45991801
110 %
111 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
112 \ifsquirrel@threeD
113 \def\squirrel@part@draw[##1]{\shade[ball color=##1]}
114 \else% 3D
115 \ifsquirrel@contour
116 \def\squirrel@part@draw[##1]{\draw[##1,\squirrel@contour,fill=white,line width=\scalingfactor*0.4pt]}
117 \else% contour
118 \def\squirrel@part@draw[##1]{\fill[##1]}
119 \fi% contour
120 \fi% 3D
121 %
122 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
123 %
124 % Body parts
125 %
126 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
127 %
128 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
129 \UseHook{tikzlings/squirrel/background}
130 \UseHook{tikzlings/background}
131 \csname squirrelhookbackground\endcsname
132 \csname tikzlinghookbackground\endcsname
133 %
134 % Feet %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135 \ifsquirrel@leftstep
136 \squirrel@part@draw[\squirrel@body!70!brown!50!darkgray] (-0.255,0.25) ellipse[x radius=0.23, y radius=0.09];
137 \else% step
138 \squirrel@part@draw[\squirrel@body!70!brown!50!darkgray] (-0.255,0.2) ellipse[x radius=0.23, y radius=0.09];
139 \fi% step
140 \ifsquirrel@rightstep
141 \squirrel@part@draw[\squirrel@body!70!brown!50!darkgray] (0.255,0.25) ellipse[x radius=0.23, y radius=0.09];
142 \else% step
143 \squirrel@part@draw[\squirrel@body!70!brown!50!darkgray] (0.255,0.2) ellipse[x radius=0.23, y radius=0.09];
144 \fi% step
145 %
146 % Tail %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
147 \unless\ifsquirrel@back
148 \squirrel@part@draw[\squirrel@body!70!brown!50!darkgray]
149 (0.9795, 1.089) .. controls (0.9795, 1.089) and (1.0684, 1.2135) .. (1.0837, 1.2877) .. controls (1.1483, 1.6164) and (0.7470, 1.8317) .. (0.5217, 1.7097) .. controls (0.3005, 1.5585) and (0.3397, 1.2578) .. (0.3951, 1.0501) .. controls (0.4419, 0.9023) and (0.5439, 0.6908) .. (0.4287, 0.5889) .. controls (0.3845, 0.5503) and (0.2295, 0.4255) .. (0.0123, 0.3869) .. controls (0.3032, 0.1931) and (1.0822, 0.6445) .. (0.8789, 1.0501) .. controls (0.8607, 1.114) and (0.8154, 1.1881) .. (0.8716, 1.2309) .. controls (0.9325, 1.2193) and (0.9536, 1.1463) .. (0.9795, 1.089) -- cycle;
150 \fi% back
151 %
152 % Body %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
153 \squirrel@part@draw[\squirrel@body] (0.5,0.5) .. controls (0.5,0.09) and (-0.5,0.09) .. (-0.5,0.5) .. controls (-0.5,0.85) and (-0.25,1.6) .. (0,1.7) .. controls (0.25,1.6) and (0.5,0.85) .. (0.5,0.5) -- cycle;
154 %
155 % Belly %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
156 \unless\ifsquirrel@back
157 \squirrel@part@draw[\squirrel@body!85!white] (0.35,0.5) .. controls (0.35,0.22) and (-0.35,0.22) .. (-0.35,0.5) .. controls (-0.35,0.7) and (-0.17,1.2) .. (0,1.2) .. controls (0.17,1.2) and (0.35,0.7) .. (0.35,0.5) -- cycle;
158 \fi% back
159 %
160 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
161 \UseHook{tikzlings/squirrel/belly}
162 \UseHook{tikzlings/belly}
163 \csname squirrelhookbelly\endcsname
164 \csname tikzlinghookbelly\endcsname
165 %
166 % Ears %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
167 \squirrel@part@draw[\squirrel@body!70!brown!50!darkgray] (0.1920,1.9906) .. controls (0.1657,2.0780) and (0.1839,2.1332) .. (0.1839,2.1332) .. controls (0.1839,2.1332) and (0.1123,2.1773) .. (0.0941,2.0720) .. controls (0.0716,2.0156) and (0.0753,1.9519) .. (0.1023,1.9293) .. controls (0.1293,1.9068) and (0.1696,1.9342) .. (0.1920,1.9906) -- cycle;
168 \squirrel@part@draw[\squirrel@body!70!brown!50!darkgray] (-0.1920,1.9906) .. controls (-0.1657,2.0780) and (-0.1839,2.1332) .. (-0.1839,2.1332) .. controls (-0.1839,2.1332) and (-0.1123,2.1773) .. (-0.0941,2.0720) .. controls (-0.0716,2.0156) and (-0.0753,1.9519) .. (-0.1023,1.9293) .. controls (-0.1293,1.9068) and (-0.1696,1.9342) .. (-0.1920,1.9906) -- cycle;
169 %
170 % Head %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
171 \ifsquirrel@contour
172 \squirrel@part@draw[\squirrel@body] (0,1.75) circle[radius=0.3];
173 \squirrel@part@draw[\squirrel@body] (0.2,1.6) circle[radius=0.15];
174 \squirrel@part@draw[\squirrel@body] (-0.2,1.6) circle[radius=0.15];
175 \ifsquirrel@back
176 \squirrel@part@draw[\squirrel@body] (0,1.75) circle[radius=0.3];
177 \fi% back
178 \else% contour
179 \squirrel@part@draw[\squirrel@body] (0,1.75) circle[radius=0.3] (0.2,1.6) circle[radius=0.15] (-0.2,1.6) circle[radius=0.15];
180 \fi% contour
181 %
182 \ifsquirrel@back
183 % Tail %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
184 \squirrel@part@draw[\squirrel@body!70!brown!50!darkgray]
185 (0.9795, 1.089) .. controls (0.9795, 1.089) and (1.0684, 1.2135) .. (1.0837, 1.2877) .. controls (1.1483, 1.6164) and (0.7470, 1.8317) .. (0.5217, 1.7097) .. controls (0.3005, 1.5585) and (0.3397, 1.2578) .. (0.3951, 1.0501) .. controls (0.4419, 0.9023) and (0.5439, 0.6908) .. (0.4287, 0.5889) .. controls (0.3845, 0.5503) and (0.2295, 0.4255) .. (0.0123, 0.3869) .. controls (0.3032, 0.1931) and (1.0822, 0.6445) .. (0.8789, 1.0501) .. controls (0.8607, 1.114) and (0.8154, 1.1881) .. (0.8716, 1.2309) .. controls (0.9325, 1.2193) and (0.9536, 1.1463) .. (0.9795, 1.089) -- cycle;
186 \else% back
187 %
188 % Nose %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
189 \squirrel@part@draw[\squirrel@body!70!brown!60!black] (0,1.66) ellipse[x radius=0.06, y radius=0.03];
190 %
191 % Eyes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
192 \squirrel@part@draw[\squirrel@eyes] (0.07,1.78) ellipse[x radius=0.05, y radius=0.07];
193 \squirrel@part@draw[\squirrel@eyes] (-0.07,1.78) ellipse[x radius=0.05, y radius=0.07];
194 \squirrel@part@draw[\squirrel@pupils] (0.07,1.76) ellipse[x radius=0.017, y radius=0.027];
195 \squirrel@part@draw[\squirrel@pupils] (-0.07,1.76) ellipse[x radius=0.017, y radius=0.027];
196 %
197 % Mouth %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
198 \ifsquirrel@contour
199 \draw[\squirrel@contour,fill=white,line width=\scalingfactor*0.4pt] (-0.15,1.61) .. controls (-0.15,1.61) and (-0.15,1.52) .. (0.0,1.61) .. controls (0.15,1.52) and (0.15,1.61) .. (0.15,1.61) (0.15,1.61) arc [start angle=-20, end angle=-160, radius=0.16];
200 \draw[\squirrel@contour,fill=white,line width=\scalingfactor*0.4pt] (-0.025,1.567) rectangle ++(0.02,0.03);
201 \draw[\squirrel@contour,fill=white,line width=\scalingfactor*0.4pt] (0.025,1.567) rectangle ++(-0.02,0.03);
202 \draw[\squirrel@contour,line width=\scalingfactor*0.4pt] (-0.15,1.61) .. controls (-0.15,1.61) and (-0.15,1.52) .. (0.0,1.61) .. controls (0.15,1.52) and (0.15,1.61) .. (0.15,1.61);
203 \else% contour
204 \ifsquirrel@openmouth
205 \filldraw[\squirrel@mouth,line width=\scalingfactor*0.4pt] (-0.15,1.61) .. controls (-0.15,1.61) and (-0.15,1.52) .. (0.0,1.61) .. controls (0.15,1.52) and (0.15,1.61) .. (0.15,1.61) (0.15,1.61) arc [start angle=-20, end angle=-160, radius=0.16];
206 \fi% open mouth
207 \fill[white] (-0.025,1.567) rectangle ++(0.02,0.03);
208 \fill[white] (0.025,1.567) rectangle ++(-0.02,0.03);
209 \draw[\squirrel@mouth,line width=\scalingfactor*0.4pt] (-0.15,1.61) .. controls (-0.15,1.61) and (-0.15,1.52) .. (0.0,1.61) .. controls (0.15,1.52) and (0.15,1.61) .. (0.15,1.61);
210 \fi% contour
211 %
212 % Arms %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
213 \squirrel@part@draw[\squirrel@body!70!brown!50!darkgray] (0.2,0.85) ellipse[x radius=0.22, y radius=0.11, rotate=70];
214 \squirrel@part@draw[\squirrel@body!70!brown!50!darkgray] (-0.2,0.85) ellipse[x radius=0.22, y radius=0.11, rotate=-70];
215 %
216 \fi% back
217 %
218 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
219 \UseHook{tikzlings/squirrel/body}
220 \UseHook{tikzlings/body}
221 \csname squirrelhookbody\endcsname
222 \csname tikzlinghookbody\endcsname
223 %
224 }
225
226 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
227 %%
228 %% Documentation
229 %%
230 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
231 %\clearpage
232 %\section[Squirrel]{Ratatosk, the squirrel}
233 %
234 %\emph{named after the squirrel from Norse mythology who climbs around Yggdrasil}
235 %
236 %\subsection{Package name}
237 %
238 %\begin{tcolorbox}[title={Package usage}]
239 %\begin{samcode}
240 %\usepackage{tikzlings-squirrels}
241 %\end{samcode}
242 %\end{tcolorbox}
243 %
244 %\subsection{Basic Usage}
245 %
246 %\begin{tcblisting}{title={Basic squirrel}}
247 %\squirrel
248 %\end{tcblisting}
249 %
250 %\subsection{Options}
251 %
252 %The basic squirrel can be modified by changing its colour:
253 %\begin{tcblisting}{title={Body colour}}
254 %\squirrel[body=blue]
255 %\end{tcblisting}
256 %
257 %In addition to the colour of the body, the colour of the eyes can be adjusted:
258 %\begin{tcblisting}{title={Eye colour}}
259 %\squirrel[eyes=red]
260 %\end{tcblisting}
261 %\begin{tcblisting}{title={Pupil colour}}
262 %\squirrel[pupils=red]
263 %\end{tcblisting}
264 %\begin{tcblisting}{title={Mouth colour}}
265 %\squirrel[mouth=red]
266 %\end{tcblisting}
267 %
268 % The squirrel can open its mouth:
269 %\begin{tcblisting}{title={Open mouth}}
270 %\squirrel[openmouth]
271 %\end{tcblisting}
272 %
273 %And the squirrel can lift its legs:
274 %\begin{tcblisting}{title={Walking}}
275 %\squirrel[leftstep]
276 %\squirrel[rightstep,xshift=2cm]
277 %\end{tcblisting}
278 %
279 %To view the squirrel from behind:
280 %\begin{tcblisting}{title={Back view}}
281 %\squirrel[back]
282 %\end{tcblisting}
283 %
284 %The key \saminline|3D| will make the squirrel 3-dimensional:
285 %\begin{tcblisting}{title={3D view}}
286 %\squirrel[3D]
287 %\end{tcblisting}
288 %
289 %And finally the \saminline|contour| key will only draw the outlines:
290 %\begin{tcblisting}{title={Contours}}
291 %\squirrel[contour=black]
292 %\end{tcblisting}