Debian Codegraph @

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

raw
1 % !TeX root = ./examples/koala.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-koalas}[2025/12/11 version v2.5 Drawing koalas in TikZ]
16
17 \RequirePackage{tikz}
18 \RequirePackage{tikzlings-addons}
19 \usetikzlibrary{shadows.blur}
20 \usetikzlibrary{fadings}
21
22 \tikzfading[name=koala@blush,inner color=transparent!50,outer color=transparent!100]
23
24 \newcommand*{\koala}[1][]{%
25 \begin{scope}%
26 \tikzset{/koala/.cd,#1}%
27 \koala@draw%
28 \end{scope}%
29 \thing[#1]%
30 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 \UseHook{tikzlings/koala/foreground}
32 \UseHook{tikzlings/koala/foreground}
33 \csname koalahookforeground\endcsname
34 \csname tikzlinghookforeground\endcsname
35 %
36 }
37
38 \newif\ifkoala@blush
39 \newif\ifkoala@sleeping
40 \newif\ifkoala@threeD
41 \newif\ifkoala@back
42 \newif\ifkoala@contour
43 \newif\ifkoala@openmouth
44
45 \NewHook{tikzlings/koala/background}
46 \NewHook{tikzlings/koala/belly}
47 \NewHook{tikzlings/koala/body}
48 \NewHook{tikzlings/koala/foreground}
49
50 \tikzset{
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 %
53 % Pass unknown keys on to tikz
54 %
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 /koala/.search also={/tikz,/pgf,/thing},
57 /koala/.cd,
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59 %
60 % body
61 %
62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63 body/.store in = \koala@body,
64 body = gray!75!white,
65 eyes/.store in = \koala@eyes,
66 eyes = black,
67 eye/.forward to = /koala/eyes,
68 mouth/.store in = \koala@mouth,
69 mouth = \koala@body!40!black,
70 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71 %
72 % options
73 %
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75 blush/.code = \koala@blushtrue
76 \def\koala@blushcolor{#1},
77 blush/.default = red,
78 sleeping/.code = \koala@sleepingtrue,
79 openmouth/.code = \koala@openmouthtrue,
80 open mouth/.forward to = /koala/openmouth,
81 3D/.code = \koala@threeDtrue
82 \def\koala@mouth{black},
83 back/.code = \koala@backtrue,
84 contour/.code = \koala@contourtrue
85 \def\koala@contour{#1}
86 \def\koala@blushcolor{#1}
87 \def\koala@mouth{#1},
88 contour/.default = black,
89 outline/.forward to = /koala/contour,
90 }
91
92 \def\koala@draw{%
93 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94 %
95 % minimal bounding box size
96 %
97 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
98 \path (-0.88,0.1) rectangle (0.88, 2.35);
99 %
100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101 %
102 % store the current scale factor
103 % from https://github.com/samcarter/tikzlings/issues/3#issuecomment-461373494
104 %
105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106 \pgfgettransformentries{\tmpscaleA}{\tmpscaleB}{\tmpscaleC}{\tmpscaleD}{\tmp}{\tmp}%
107 \pgfmathsetmacro{\scalingfactor}{sqrt(abs(\tmpscaleA*\tmpscaleD-\tmpscaleB*\tmpscaleC))*sqrt(abs((\pgf@xx/1cm)*(\pgf@yy/1cm)-(\pgf@xy/1cm)*(\pgf@yx/1cm)))}%
108 \pgfmathsetmacro{\xscalefactor}{\tmpscaleA}
109 \pgfmathsetmacro{\yscalefactor}{\tmpscaleD}
110 %
111 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
112 %
113 % switch between 2D, 3D and contours, from
114 % https://chat.stackexchange.com/transcript/message/45991801#45991801
115 %
116 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117 \ifkoala@threeD
118 \def\koala@part@draw[##1]{\shade[ball color=##1]}
119 \else% 3D
120 \ifkoala@contour
121 \def\koala@part@draw[##1]{\draw[##1,\koala@contour,fill=white,line width=\scalingfactor*0.4pt]}
122 \else% contour
123 \def\koala@part@draw[##1]{\fill[##1]}
124 \fi% contour
125 \fi% 3D
126 %
127 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128 %
129 % Body parts
130 %
131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
132 %
133 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134 \UseHook{tikzlings/koala/background}
135 \UseHook{tikzlings/koala/background}
136 \csname koalahookbackground\endcsname
137 \csname tikzlinghookbackground\endcsname
138 %
139 % Feet %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
140 \koala@part@draw[\koala@body!50!black] (0.255,0.2) ellipse[x radius=0.23, y radius=0.09];
141 \koala@part@draw[\koala@body!50!black] (-0.255,0.2) ellipse[x radius=0.23, y radius=0.09];
142 %
143 % Ears %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
144 \koala@part@draw[\koala@body] (0.405, 2.1) ellipse[x radius=0.3, y radius=0.23];
145 \koala@part@draw[\koala@body] (-0.405, 2.1) ellipse[x radius=0.3, y radius=0.23];
146 \unless\ifkoala@back
147 \koala@part@draw[\koala@body!40!white] (-0.405, 2.1) ellipse[x radius=0.15, y radius=0.12];
148 \koala@part@draw[\koala@body!40!white] (0.405, 2.1) ellipse[x radius=0.15, y radius=0.12];
149 \fi% back
150 %
151 % Arms %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
152 \koala@part@draw[\koala@body] (-0.625,1) ellipse[x radius=0.42, y radius=0.13, rotate=70];
153 \koala@part@draw[\koala@body!50!black] (-0.745,0.65) ellipse[x radius=0.12, y radius=0.08, rotate=-20];
154 \koala@part@draw[\koala@body] (0.625,1) ellipse[x radius=0.42, y radius=0.13, rotate=-70];
155 \koala@part@draw[\koala@body!50!black] (0.745,0.65) ellipse[x radius=0.12, y radius=0.08, rotate=20];
156 %
157 % Body %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
158 \koala@part@draw[\koala@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;
159 %
160 % Belly %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
161 \unless\ifkoala@back
162 \koala@part@draw[\koala@body!40!white] ( 0.425, 0.71) .. controls ( 0.425, 0.41) and ( 0.255, 0.27) .. ( 0 , 0.27) .. controls (-0.255, 0.27) and (-0.425, 0.41) .. (-0.425, 0.71) .. controls (-0.425, 1.01) and (-0.255, 1.20) .. ( 0 , 1.20) .. controls ( 0.225, 1.20) and ( 0.425, 1.01) .. ( 0.425, 0.71) -- cycle;
163 \fi% back
164 %
165 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
166 \UseHook{tikzlings/koala/belly}
167 \UseHook{tikzlings/koala/belly}
168 \csname koalahookbelly\endcsname
169 \csname tikzlinghookbelly\endcsname
170 %
171 % Head %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
172 \koala@part@draw[\koala@body] (0,1.67) ellipse[x radius=0.55, y radius=0.45];
173 %
174 % Show details only from the front %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
175 \unless\ifkoala@back
176 %
177 % Nose %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
178 \koala@part@draw[\koala@body!40!black] (-0.1501, 1.5609) .. controls (-0.1784, 1.4833) and (-0.0827, 1.4108) .. ( 0.0000, 1.4108) .. controls ( 0.0827, 1.4108) and ( 0.1784, 1.4833) .. ( 0.1501, 1.5609) .. controls ( 0.1290, 1.6191) and ( 0.1187, 1.6573) .. ( 0.0750, 1.7010) .. controls ( 0.0336, 1.7424) and (-0.0336, 1.7424) .. (-0.0750, 1.7010) .. controls (-0.1187, 1.6573) and (-0.1290, 1.6191) .. (-0.1501, 1.5609) -- cycle;
179 %
180 % Eyes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181 \ifkoala@sleeping
182 \fill[\koala@body!50!black] (0.2534, 1.675) rectangle ++(0.005, 0.03);
183 \fill[\koala@body!50!black,rotate around={20:(0.2925, 1.6925)}] (0.29, 1.68) rectangle ++(0.005, 0.03);
184 \fill[\koala@body!50!black,rotate around={-20:(0.2143, 1.6925)}] (0.2168, 1.68) rectangle ++(0.005, 0.03);
185 \fill[\koala@body!50!black,rotate around={40:(0.3255, 1.7025)}] (0.323, 1.69) rectangle ++(0.005, 0.03);
186 \fill[\koala@body!50!black,rotate around={-40:(0.1813, 1.7025)}] (0.1838, 1.69) rectangle ++(0.005, 0.03);
187 \fill[\koala@body!50!black] (-0.2534, 1.675) rectangle ++(-0.005, 0.03);
188 \fill[\koala@body!50!black,rotate around={-20:(-0.2925, 1.6925)}] (-0.29, 1.68) rectangle ++(-0.005, 0.03);
189 \fill[\koala@body!50!black,rotate around={20:(-0.2143, 1.6925)}] (-0.2168, 1.68) rectangle ++(-0.005, 0.03);
190 \fill[\koala@body!50!black,rotate around={-40:(-0.3255, 1.7025)}] (-0.323, 1.69) rectangle ++(-0.005, 0.03);
191 \fill[\koala@body!50!black,rotate around={40:(-0.1813, 1.7025)}] (-0.1838, 1.69) rectangle ++(-0.005, 0.03);
192 \fill[\koala@body!50!black, even odd rule] (0.3331, 1.741) .. controls (0.3331, 1.685) and (0.1737, 1.685) .. (0.1737, 1.741) .. controls (0.1737, 1.848) and (0.3331, 1.848) .. (0.3331, 1.741) -- cycle (0.328, 1.741) .. controls (0.323, 1.705) and (0.184, 1.705) .. (0.179, 1.741) .. controls (0.184, 1.843) and (0.323, 1.843) .. (0.328, 1.741) -- cycle;
193 \fill[\koala@body!50!black, even odd rule] (-0.3331, 1.741) .. controls (-0.3331, 1.685) and (-0.1737, 1.685) .. (-0.1737, 1.741) .. controls (-0.1737, 1.848) and (-0.3331, 1.848) .. (-0.3331, 1.741) -- cycle (-0.328, 1.741) .. controls (-0.323, 1.705) and (-0.184, 1.705) .. (-0.179, 1.741) .. controls (-0.184, 1.843) and (-0.323, 1.843) .. (-0.328, 1.741) -- cycle;
194 \else% sleeping
195 \koala@part@draw[\koala@eyes] (-0.255, 1.74) circle[radius=0.08];
196 \koala@part@draw[\koala@eyes] (0.255, 1.74) circle[radius=0.08];
197 \fill[white] (-0.27, 1.76) circle[radius=0.015];
198 \fill[white] (0.24, 1.76) circle[radius=0.015];
199 \fi% sleeping
200 %
201 % Mouth %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
202 \ifkoala@openmouth
203 \filldraw[\koala@mouth,line width=\scalingfactor*0.4pt] (0.115, 1.39) arc [start angle=-40, end angle=-140, radius=0.16];
204 \else
205 \draw[\koala@mouth,line width=\scalingfactor*0.4pt] (0.115, 1.39) arc [start angle=-40, end angle=-140, radius=0.16];
206 \fi
207 %
208 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
209 %
210 % optional
211 %
212 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
213 %
214 % Blushed %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
215 \ifkoala@blush
216 \fill[\koala@blushcolor,path fading=koala@blush] (-0.3, 1.52) circle[radius=0.1];
217 \fill[\koala@blushcolor,path fading=koala@blush] (0.3, 1.52) circle[radius=0.1];
218 \fi% blush
219 %
220 \fi% back
221 %
222 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
223 \UseHook{tikzlings/koala/body}
224 \UseHook{tikzlings/koala/body}
225 \csname koalahookbody\endcsname
226 \csname tikzlinghookbody\endcsname
227 %
228 }
229
230 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
231 %%
232 %% Documentation
233 %%
234 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
235 %\clearpage
236 %\section[Koala]{Will, the koala}
237 %
238 %\emph{The koala was generously contributed by @marmot and is named in honour of a \LaTeX{} developer from Down Under}
239 %
240 %\subsection{Package name}
241 %
242 %\begin{tcolorbox}[title={Package usage}]
243 %\begin{samcode}
244 %\usepackage{tikzlings-koalas}
245 %\end{samcode}
246 %\end{tcolorbox}
247 %
248 %\subsection{Basic Usage}
249 %
250 %\begin{tcblisting}{title={Basic koala}}
251 %\koala
252 %\end{tcblisting}
253 %
254 %\subsection{Options}
255 %
256 %The basic koala can be modified by changing its colour:
257 %\begin{tcblisting}{title={Body colour}}
258 %\koala[body=blue]
259 %\end{tcblisting}
260 %
261 %In addition to the colour of the body, the colour of various body parts can be adjusted:
262 %\begin{tcblisting}{title={Eye colour}}
263 %\koala[eyes=red]
264 %\end{tcblisting}
265 %\begin{tcblisting}{title={Mouth colour}}
266 %\koala[mouth=red]
267 %\end{tcblisting}
268 %
269 % The koala can open its mouth:
270 %\begin{tcblisting}{title={Open mouth}}
271 %\koala[openmouth]
272 %\end{tcblisting}
273 %
274 %It can also blush
275 %\begin{tcblisting}{title={Blushing koala}}
276 %\koala[blush=red]
277 %\end{tcblisting}
278 %
279 %and if tired, it is going to take a nap:
280 %\begin{tcblisting}{title={Sleep}}
281 %\koala[sleeping]
282 %\end{tcblisting}
283 %
284 %To view the koala from behind:
285 %\begin{tcblisting}{title={Back view}}
286 %\koala[back]
287 %\end{tcblisting}
288 %
289 %The key \saminline|3D| will make the koala 3-dimensional:
290 %\begin{tcblisting}{title={3D view}}
291 %\koala[3D]
292 %\end{tcblisting}
293 %
294 %And finally the \saminline|contour| key will only draw the outlines:
295 %\begin{tcblisting}{title={Contours}}
296 %\koala[contour=black]
297 %\end{tcblisting}