Debian Codegraph @

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

raw
1 % !TeX root = ./examples/anteater.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-anteaters}[2025/12/11 version v2.5 Drawing anteaters in TikZ]
16
17 \RequirePackage{tikz}
18 \RequirePackage{tikzlings-addons}
19
20 \newcommand*{\anteater}[1][]{%
21 \begin{scope}%
22 \tikzset{/anteater/.cd,#1}%
23 \anteater@draw%
24 \end{scope}%
25 \thing[#1]%
26 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27 \UseHook{tikzlings/anteater/foreground}
28 \UseHook{tikzlings/foreground}
29 \csname anteaterhookforeground\endcsname
30 \csname tikzlinghookforeground\endcsname
31 }
32
33 \newif\ifanteater@threeD
34 \newif\ifanteater@back
35 \newif\ifanteater@contour
36 \newif\ifanteater@leftstep
37 \newif\ifanteater@rightstep
38
39 \NewHook{tikzlings/anteater/background}
40 \NewHook{tikzlings/anteater/belly}
41 \NewHook{tikzlings/anteater/body}
42 \NewHook{tikzlings/anteater/foreground}
43
44 \tikzset{
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46 %
47 % Pass unknown keys on to tikz
48 %
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 /anteater/.search also={/tikz,/pgf,/thing},
51 /anteater/.cd,
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 %
54 % body
55 %
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 body/.store in = \anteater@body,
58 body = red!55!green!75!blue!66!white,
59 eyes/.store in = \anteater@eyes,
60 eyes = \anteater@body!70!brown!50!darkgray,
61 eye/.forward to = /anteater/eyes,
62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63 %
64 % options
65 %
66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 3D/.code = \anteater@threeDtrue,
68 leftstep/.code = \anteater@leftsteptrue,
69 left step/.forward to = /anteater/leftstep,
70 rightstep/.code = \anteater@rightsteptrue,
71 right step/.forward to = /anteater/rightstep,
72 back/.code = \anteater@backtrue,
73 contour/.code = \anteater@contourtrue
74 \def\anteater@contour{#1},
75 contour/.default = black,
76 outline/.forward to = /anteater/contour,
77 }
78
79 \def\anteater@draw{%
80 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 %
82 % minimal bounding box size
83 %
84 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85 \path (-0.75,0.1) rectangle (1.12,2.26);
86 %
87 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88 %
89 % store the current scale factor
90 % from
91 % https://github.com/samcarter/tikzlings/issues/3#issuecomment-461373494
92 %
93 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94 \pgfgettransformentries{\tmpscaleA}{\tmpscaleB}{\tmpscaleC}{\tmpscaleD}{\tmp}{\tmp}%
95 \pgfmathsetmacro{\scalingfactor}{sqrt(abs(\tmpscaleA*\tmpscaleD-\tmpscaleB*\tmpscaleC))*sqrt(abs((\pgf@xx/1cm)*(\pgf@yy/1cm)-(\pgf@xy/1cm)*(\pgf@yx/1cm)))}%
96 \pgfmathsetmacro{\xscalefactor}{\tmpscaleA}
97 \pgfmathsetmacro{\yscalefactor}{\tmpscaleD}
98 %
99 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100 %
101 % switch between 2D, 3D and contours, from
102 % https://chat.stackexchange.com/transcript/message/45991801#45991801
103 %
104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105 \ifanteater@threeD
106 \def\anteater@part@draw[##1]{\shade[ball color=##1]}
107 \else% 3D
108 \ifanteater@contour
109 \def\anteater@part@draw[##1]{\draw[##1,\anteater@contour,fill=white,line width=\scalingfactor*0.4pt]}
110 \else% contour
111 \def\anteater@part@draw[##1]{\fill[##1]}
112 \fi% contour
113 \fi% 3D
114 %
115 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
116 %
117 % Body parts
118 %
119 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120 %
121 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
122 \UseHook{tikzlings/anteater/background}
123 \UseHook{tikzlings/background}
124 \csname anteaterhookbackground\endcsname
125 \csname tikzlinghookbackground\endcsname
126 %
127 % Feet %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128 \ifanteater@leftstep
129 \anteater@part@draw[\anteater@body!70!brown!50!darkgray] (-0.255,0.25) ellipse[x radius=0.23, y radius=0.09];
130 \else% step
131 \anteater@part@draw[\anteater@body!70!brown!50!darkgray] (-0.255,0.2) ellipse[x radius=0.23, y radius=0.09];
132 \fi% step
133 %
134 \ifanteater@rightstep
135 \anteater@part@draw[\anteater@body!70!brown!50!darkgray] (0.255,0.25) ellipse[x radius=0.23, y radius=0.09];
136 \else% step
137 \anteater@part@draw[\anteater@body!70!brown!50!darkgray] (0.255,0.2) ellipse[x radius=0.23, y radius=0.09];
138 \fi% step
139 %
140 % Tail %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141 \unless\ifanteater@back
142 \anteater@part@draw[\anteater@body!70!brown!50!darkgray] (1.0893, 1.5779) .. controls (0.3433, 1.6612) and (0.4863, 0.6062) .. (-0.0243, 0.348) .. controls (1.0671, 0.068) and (0.8133, 1.1808) .. (1.0893, 1.5779) -- cycle;
143 \fi% back
144 %
145 % Arms %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146 \anteater@part@draw[\anteater@body!45!white!95!orange] (-0.55,1) ellipse[x radius=0.42, y radius=0.13, rotate=70] (0.55,1) ellipse[x radius=0.42, y radius=0.13, rotate=-70];
147 %
148 % Body %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
149 \anteater@part@draw[\anteater@body] (0.52, 0.8) .. controls (0.52, 0.23) and (0.3, 0.17) .. (0, 0.17) .. controls (-0.3, 0.17) and (-0.52, 0.23) .. (-0.52, 0.8) .. controls (-0.52, 1.35) and (-0.3, 1.8) .. (0, 1.8) .. controls (0.3, 1.8) and (0.52, 1.35) .. (0.52, 0.8) -- cycle;
150 %
151 % Collar %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
152 \ifanteater@back
153 \anteater@part@draw[\anteater@body!45!white!95!orange] (-0,1.47) ellipse [x radius=0.36, y radius=0.28];
154 \anteater@part@draw[\anteater@body!70!brown!50!darkgray] (-0,1.47) ellipse [x radius=0.35, y radius=0.23];
155 \else% back
156 \anteater@part@draw[\anteater@body!45!white!95!orange] (0.33, 1.55) -- (-0.33, 1.55) .. controls (-0.5, 1.05) and (-0.1, 0.95) .. (0, 0.60) .. controls (0.1, 0.95) and (0.5, 1.05) .. (0.33, 1.55) -- cycle;
157 \anteater@part@draw[\anteater@body!70!brown!50!darkgray] (0.33, 1.55) -- (-0.33, 1.55) .. controls (-0.45, 1.1) and (-0.1, 1) .. (0, 0.70) .. controls (0.1, 1) and (0.45, 1.1) .. (0.33, 1.55) -- cycle;
158 \fi% back
159 %
160 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
161 \UseHook{tikzlings/anteater/belly}
162 \UseHook{tikzlings/belly}
163 \csname anteaterhookbelly\endcsname
164 \csname tikzlinghookbelly\endcsname
165 %
166 \ifanteater@back
167 % Head %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
168 \anteater@part@draw[\anteater@body] (-0,1.73) ellipse [x radius=0.36, y radius=0.33];
169 %
170 % Ears %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
171 \anteater@part@draw[\anteater@body!70!brown!50!darkgray] (0.5551, 2.2281) .. controls (0.4961, 2.2273) and (0.4390, 2.2093) .. (0.3831, 2.1919) .. controls (0.3282, 2.173) and (0.2725, 2.1539) .. (0.2231, 2.1228) .. controls (0.1875, 2.0984) and (0.1524, 2.0637) .. (0.1470, 2.0187) .. controls (0.1446, 2.0028) and (0.1518, 1.9881) .. (0.1584, 1.9744) .. controls (0.1706, 1.9343) and (0.2090, 1.9063) .. (0.25, 1.9017) .. controls (0.3079, 1.8943) and (0.3684, 1.9134) .. (0.4132, 1.9504) .. controls (0.4657, 1.9988) and (0.5111, 2.0545) .. (0.5513, 2.1133) .. controls (0.5692, 2.1404) and (0.5854, 2.1692) .. (0.5945, 2.2004) .. controls (0.5989, 2.2232) and (0.5717, 2.2282) .. (0.5551, 2.2281) -- cycle;
172 \anteater@part@draw[\anteater@body!70!brown!50!darkgray] (-0.5551, 2.2281) .. controls (-0.4961, 2.2273) and (-0.4390, 2.2093) .. (-0.3831, 2.1919) .. controls (-0.3282, 2.173) and (-0.2725, 2.1539) .. (-0.2231, 2.1228) .. controls (-0.1875, 2.0984) and (-0.1524, 2.0637) .. (-0.1470, 2.0187) .. controls (-0.1446, 2.0028) and (-0.1518, 1.9881) .. (-0.1584, 1.9744) .. controls (-0.1706, 1.9343) and (-0.2090, 1.9063) .. (-0.25, 1.9017) .. controls (-0.3079, 1.8943) and (-0.3684, 1.9134) .. (-0.4132, 1.9504) .. controls (-0.4657, 1.9988) and (-0.5111, 2.0545) .. (-0.5513, 2.1133) .. controls (-0.5692, 2.1404) and (-0.5854, 2.1692) .. (-0.5945, 2.2004) .. controls (-0.5989, 2.2232) and (-0.5717, 2.2282) .. (-0.5551, 2.2281) -- cycle;
173 %
174 \else% back
175 %
176 % Ears %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
177 \anteater@part@draw[\anteater@body!70!brown!50!darkgray] (0.3531, 1.9773) .. controls (0.4315, 2.0197) and (0.6217, 2.172) .. (0.5917, 2.2157) .. controls (0.5615, 2.2594) and (0.3224, 2.178) .. (0.2441, 2.1354) .. controls (0.1659, 2.093) and (0.1269, 2.023) .. (0.1569, 1.9793) .. controls (0.1870, 1.9356) and (0.2748, 1.9347) .. (0.3531, 1.9773) -- cycle;
178 \anteater@part@draw[\anteater@body!70!brown!50!darkgray] (-0.3531, 1.9773) .. controls (-0.4315, 2.0197) and (-0.6217, 2.172) .. (-0.5917, 2.2157) .. controls (-0.5615, 2.2594) and (-0.3224, 2.178) .. (-0.2441, 2.1354) .. controls (-0.1659, 2.093) and (-0.1269, 2.023) .. (-0.1569, 1.9793) .. controls (-0.1870, 1.9356) and (-0.2748, 1.9347) .. (-0.3531, 1.9773) -- cycle;
179 \anteater@part@draw[\anteater@body!45!white!95!orange] (0.4086, 1.9465) .. controls (0.4679, 1.9952) and (0.6205, 2.1813) .. (0.5862, 2.2146) .. controls (0.5517, 2.2477) and (0.3434, 2.1152) .. (0.2841, 2.0665) .. controls (0.2249, 2.0177) and (0.2048, 1.9515) .. (0.2391, 1.9184) .. controls (0.2736, 1.8853) and (0.3494, 1.8979) .. (0.40861, 1.9465) -- cycle
180 (-0.4086, 1.9465) .. controls (-0.4679, 1.9952) and (-0.6205, 2.1813) .. (-0.5862, 2.2146) .. controls (-0.5517, 2.2477) and (-0.3434, 2.1152) .. (-0.2841, 2.0665) .. controls (-0.2249, 2.0177) and (-0.2048, 1.9515) .. (-0.2391, 1.9184) .. controls (-0.2736, 1.8853) and (-0.3494, 1.8979) .. (-0.40861, 1.9465) -- cycle;
181 %
182 % Head %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
183 \anteater@part@draw[\anteater@body] (0.33, 1.71) .. controls (0.16, 1.52) and (0.1, 1.5) .. (0.08, 1.05) .. controls (0.07, 1) and (-0.07, 1) .. (-0.08, 1.05) .. controls (-0.1, 1.5) and (-0.16, 1.52) .. (-0.33, 1.7) .. controls (-0.45, 1.85) and (-0.22, 2.05) .. (0, 2.05) .. controls (0.22, 2.05) and (0.45, 1.85) .. (0.33, 1.7) -- cycle;
184 %
185 % Cheeks %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
186 \anteater@part@draw[\anteater@body!45!white!95!orange] (0.3508, 1.739) .. controls (0.3508, 1.739) and (0.2861, 1.8489) .. (0.1571, 1.7664) .. controls (0.0279, 1.684) and (0.0627, 1.0524) .. (0.0627, 1.0524) .. controls (0.0627, 1.0524) and (0.131, 1.3772) .. (0.2314, 1.44) .. controls (0.3599, 1.5206) and (0.3508, 1.739) .. (0.3508, 1.739) -- cycle
187 (-0.3508, 1.739) .. controls (-0.3508, 1.739) and (-0.2861, 1.8489) .. (-0.1571, 1.7664) .. controls (-0.0279, 1.684) and (-0.0627, 1.0524) .. (-0.0627, 1.0524) .. controls (-0.0627, 1.0524) and (-0.131, 1.3772) .. (-0.2314, 1.44) .. controls (-0.3599, 1.5206) and (-0.3508, 1.739) .. (-0.3508, 1.739) -- cycle;
188 %
189 % Nose %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
190 \anteater@part@draw[\anteater@body!70!brown!50!darkgray] (0, 1.08) ellipse[x radius=0.08, y radius=0.05];
191 %
192 % Eyes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
193 \anteater@part@draw[\anteater@eyes] (0.23, 1.7) circle[radius=0.05];
194 \anteater@part@draw[\anteater@eyes] (-0.23, 1.7) circle[radius=0.05];
195 \fi% back
196 %
197 % Tail if back %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
198 \ifanteater@back
199 \anteater@part@draw[\anteater@body!70!brown!50!darkgray] (1.0893, 1.5779) .. controls (0.3433, 1.6612) and (0.4863, 0.6062) .. (-0.0243, 0.348) .. controls (1.0671, 0.068) and (0.8133, 1.1808) .. (1.0893, 1.5779) -- cycle;
200 \fi% back
201 %
202 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203 \UseHook{tikzlings/anteater/body}
204 \UseHook{tikzlings/body}
205 \csname anteaterhookbody\endcsname
206 \csname tikzlinghookbody\endcsname
207 %
208 }
209
210 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
211 %%
212 %% Documentation
213 %%
214 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
215 %\clearpage
216 %\section[Anteater]{Peter, the anteater}
217 %
218 %\subsection{Package name}
219 %
220 %\begin{tcolorbox}[title={Package usage}]
221 %\begin{samcode}
222 %\usepackage{tikzlings-anteaters}
223 %\end{samcode}
224 %\end{tcolorbox}
225 %
226 %\subsection{Basic Usage}
227 %
228 %\begin{tcblisting}{title={Basic anteater}}
229 %\anteater
230 %\end{tcblisting}
231 %
232 %\subsection{Options}
233 %
234 %The basic anteater can be modified by changing its colour:
235 %\begin{tcblisting}{title={Body colour}}
236 %\anteater[body=blue]
237 %\end{tcblisting}
238 %
239 %In addition to the colour of the body, the colour of the eyes can be adjusted:
240 %\begin{tcblisting}{title={Eye colour}}
241 %\anteater[eyes=red]
242 %\end{tcblisting}
243 %
244 %And the anteater can lift its legs:
245 %\begin{tcblisting}{title={Walking}}
246 %\anteater[leftstep]
247 %\anteater[rightstep,xshift=2cm]
248 %\end{tcblisting}
249 %
250 %To view the anteater from behind:
251 %\begin{tcblisting}{title={Back view}}
252 %\anteater[back]
253 %\end{tcblisting}
254 %
255 %The key \saminline|3D| will make the anteater 3-dimensional:
256 %\begin{tcblisting}{title={3D view}}
257 %\anteater[3D]
258 %\end{tcblisting}
259 %
260 %And finally the \saminline|contour| key will only draw the outlines:
261 %\begin{tcblisting}{title={Contours}}
262 %\anteater[contour=black]
263 %\end{tcblisting}