Debian Codegraph @

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

raw
1 % !TeX root = ./examples/turkey.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-turkeys}[2025/12/11 version v2.5 Draw turkeys in TikZ]
16
17 \RequirePackage{tikz}
18 \RequirePackage{tikzlings-addons}
19
20 \newcommand*{\turkey}[1][]{%
21 \begin{scope}%
22 \tikzset{/turkey/.cd,#1}%
23 \turkey@draw%
24 \end{scope}%
25 \thing[#1]%
26 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27 \UseHook{tikzlings/turkey/foreground}
28 \UseHook{tikzlings/foreground}
29 \csname turkeyhookforeground\endcsname
30 \csname tikzlinghookforeground\endcsname
31 %
32 }
33
34 \newif\ifturkey@threeD
35 \newif\ifturkey@back
36 \newif\ifturkey@contour
37 \newif\ifturkey@baby
38
39 \NewHook{tikzlings/turkey/background}
40 \NewHook{tikzlings/turkey/belly}
41 \NewHook{tikzlings/turkey/body}
42 \NewHook{tikzlings/turkey/foreground}
43
44 \tikzset{
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46 %
47 % Pass unknown keys on to tikz
48 %
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 /turkey/.search also={/tikz,/pgf,/thing},
51 /turkey/.cd,
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 %
54 % body
55 %
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 body/.store in = \turkey@body,
58 body = brown!70!black,
59 eyes/.store in = \turkey@eyes,
60 eyes = brown!30!black,
61 eye/.forward to = /turkey/eyes,
62 bill/.store in = \turkey@bill,
63 bill = yellow!50!orange,
64 feet/.store in = \turkey@feet,
65 feet = orange!90!yellow,
66 foot/.forward to = /turkey/feet,
67 wattle/.store in = \turkey@wattle,
68 wattle = red!70!black,
69 head/.store in = \turkey@head,
70 head = \turkey@body!80!white,
71 wings/.store in = \turkey@wings,
72 wings = \turkey@body!80!black,
73 wing/.forward to = /turkey/wings,
74 tail/.store in = \turkey@tail,
75 tail = \turkey@body!80!white,
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 %
78 % options
79 %
80 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 3D/.code = \turkey@threeDtrue,
82 back/.code = \turkey@backtrue,
83 contour/.code = \turkey@contourtrue
84 \def\turkey@contour{#1},
85 contour/.default = black,
86 outline/.forward to = /turkey/contour,
87 }
88
89 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90 %%
91 %% Grown up turkey
92 %%
93 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94 \def\turkey@draw{%
95 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 %
97 % minimal bounding box size
98 %
99 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100 \path (-0.97, 0.08) rectangle (0.97, 2.2);
101 %
102 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
103 %
104 % store the current scale factor
105 % from https://github.com/samcarter/tikzlings/issues/3#issuecomment-461373494
106 %
107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108 \pgfgettransformentries{\tmpscaleA}{\tmpscaleB}{\tmpscaleC}{\tmpscaleD}{\tmp}{\tmp}%
109 \pgfmathsetmacro{\scalingfactor}{sqrt(abs(\tmpscaleA*\tmpscaleD-\tmpscaleB*\tmpscaleC))*sqrt(abs((\pgf@xx/1cm)*(\pgf@yy/1cm)-(\pgf@xy/1cm)*(\pgf@yx/1cm)))}%
110 \pgfmathsetmacro{\xscalefactor}{\tmpscaleA}
111 \pgfmathsetmacro{\yscalefactor}{\tmpscaleD}
112 %
113 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114 %
115 % switch between 2D, 3D and contours, from
116 % https://chat.stackexchange.com/transcript/message/45991801#45991801
117 %
118 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
119 \ifturkey@threeD
120 \def\turkey@part@draw[##1]{\shade[ball color=##1]}
121 \else% 3D
122 \ifturkey@contour
123 \def\turkey@part@draw[##1]{\draw[##1,\turkey@contour,fill=white,line width=\scalingfactor*0.4pt]}
124 \else% contour
125 \def\turkey@part@draw[##1]{\fill[##1]}
126 \fi% contour
127 \fi% 3D
128 %
129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130 %
131 % Body parts
132 %
133 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134 %
135 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136 \UseHook{tikzlings/turkey/background}
137 \UseHook{tikzlings/background}
138 \csname turkeyhookbackground\endcsname
139 \csname tikzlinghookbackground\endcsname
140 %
141 % Tail %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
142 \unless\ifturkey@back
143 \foreach \tmp in {-40,0,...,210}{
144 \turkey@part@draw[\turkey@tail!70] (0,1)++(\tmp:0.45) ellipse[x radius=0.5, y radius=0.15, rotate=\tmp];
145 \turkey@part@draw[\turkey@tail] (0,1)++(\tmp+20:0.45) ellipse[x radius=0.5, y radius=0.15, rotate=\tmp+20];
146 }
147 \fi
148 %
149 % Feet %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
150 \turkey@part@draw[\turkey@feet] (0.19,0.4) ellipse[x radius=0.03, y radius=0.2];
151 \turkey@part@draw[\turkey@feet] (-0.19,0.4) ellipse[x radius=0.03, y radius=0.2];
152 \turkey@part@draw[\turkey@feet] (0.175,0.2) ellipse[x radius=0.03, y radius=0.1];
153 \turkey@part@draw[\turkey@feet] (0.225,0.21) ellipse[x radius=0.03, y radius=0.1, rotate=20];
154 \turkey@part@draw[\turkey@feet] (0.275,0.23) ellipse[x radius=0.03, y radius=0.1, rotate=40];
155 \turkey@part@draw[\turkey@feet] (-0.175,0.2) ellipse[x radius=0.03, y radius=0.1];
156 \turkey@part@draw[\turkey@feet] (-0.225,0.21) ellipse[x radius=0.03, y radius=0.1, rotate=-20];
157 \turkey@part@draw[\turkey@feet] (-0.275,0.23) ellipse[x radius=0.03, y radius=0.1, rotate=-40];
158 %
159 % Body %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
160 \turkey@part@draw[\turkey@body] (0.18,0.55) circle [radius=0.1];
161 \turkey@part@draw[\turkey@body] (-0.18,0.55) circle [radius=0.1];
162 \turkey@part@draw[\turkey@body] (0,1) circle [radius=0.5];
163 %
164 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
165 \UseHook{tikzlings/turkey/belly}
166 \UseHook{tikzlings/belly}
167 \csname turkeyhookbelly\endcsname
168 \csname tikzlinghookbelly\endcsname
169 %
170 % Neck %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
171 \turkey@part@draw[\turkey@head] (0.1,1.8) -- ++(-0.2,0) --++(0,-0.7) arc [start angle=180, end angle=360, radius=0.1] -- cycle;
172 %
173 % Head %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
174 \turkey@part@draw[\turkey@head] (0.09, 1.98) .. controls (0.09, 1.98) and (0.13, 2.17) .. (0.07, 2.19) .. controls (0.09, 2.05) and (-0.04, 2) .. (-0.04, 2) .. controls (-0.04, 2) and (-0.02, 2.12) .. (-0.06, 2.13) .. controls (-0.06, 2.03) and (-0.13, 2) .. (-0.13, 2) -- cycle;
175 \turkey@part@draw[\turkey@head] (0,1.75) circle [radius=0.28];
176 %
177 % Eyes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
178 \unless\ifturkey@back
179 \turkey@part@draw[\turkey@eyes] (0.124,1.78) circle[radius=0.03];
180 \turkey@part@draw[\turkey@eyes] (-0.124,1.78) circle[radius=0.03];
181 \fi% back
182 %
183 % Bill %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
184 \unless\ifturkey@back
185 \turkey@part@draw[\turkey@bill] (0, 1.58) -- ++(115:0.12) arc [start angle=115, end angle=65, radius=0.12] -- cycle;
186 \turkey@part@draw[\turkey@wattle] (0.019, 1.703).. controls (-0.117, 1.781) and (-0.134, 1.550) .. (-0.085, 1.532).. controls (-0.0334, 1.513) and (-0.069, 1.687) .. (0.0187, 1.703) -- cycle;
187 \fi% back
188 %
189 % Wings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
190 \turkey@part@draw[\turkey@wings] (0.45,0.5) arc[start angle=-35, end angle=65, radius=0.65] -- cycle;
191 \turkey@part@draw[\turkey@wings] (-0.45,0.5) arc[end angle=115, start angle=215, radius=0.65] -- cycle;
192 %
193 % Tail %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
194 \ifturkey@back
195 \foreach \tmp in {-40,0,...,210}{
196 \turkey@part@draw[\turkey@tail] (0,1)++(\tmp:0.45) ellipse[x radius=0.5, y radius=0.15, rotate=\tmp];
197 \turkey@part@draw[\turkey@tail!70] (0,1)++(\tmp+20:0.45) ellipse[x radius=0.5, y radius=0.15, rotate=\tmp+20];
198 }
199 \fi
200 %
201 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
202 \UseHook{tikzlings/turkey/body}
203 \UseHook{tikzlings/body}
204 \csname turkeyhookbody\endcsname
205 \csname tikzlinghookbody\endcsname
206 %
207 }
208
209 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
210 %%
211 %% Documentation
212 %%
213 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
214 %\clearpage
215 %\section[Turkey]{Karl, the turkey}
216 %
217 %\emph{Named after @karlh, whose question\footnote{\url{https://tex.stackexchange.com/q/755365/36296}} inspired the turkey.}
218 %
219 %\subsection{Package name}
220 %
221 %\begin{tcolorbox}[title={Package usage}]
222 %\begin{samcode}
223 %\usepackage{tikzlings-turkeys}
224 %\end{samcode}
225 %\end{tcolorbox}
226 %
227 %\subsection{Basic Usage}
228 %
229 %\begin{tcblisting}{title={Basic turkey}}
230 %\turkey
231 %\end{tcblisting}
232 %
233 %\subsection{Options}
234 %
235 %The basic turkey can be modified by changing its colour:
236 %\begin{tcblisting}{title={Body colour}}
237 %\turkey[body=blue]
238 %\end{tcblisting}
239 %
240 %In addition to the colour of the body, the colour of various body parts can be adjusted:
241 %\begin{tcblisting}{title={Head colour}}
242 %\turkey[head=red]
243 %\end{tcblisting}
244 %
245 %\begin{tcblisting}{title={Wattle colour}}
246 %\turkey[wattle=green]
247 %\end{tcblisting}
248 %
249 %\begin{tcblisting}{title={Eye colour}}
250 %\turkey[eyes=red]
251 %\end{tcblisting}
252 %
253 %\begin{tcblisting}{title={Bill colour}}
254 %\turkey[bill=red]
255 %\end{tcblisting}
256 %
257 %\begin{tcblisting}{title={Foot colour}}
258 %\turkey[feet=red]
259 %\end{tcblisting}
260 %
261 %\begin{tcblisting}{title={Wing colour}}
262 %\turkey[wings=red]
263 %\end{tcblisting}
264 %
265 %\begin{tcblisting}{title={Tail colour}}
266 %\turkey[tail=red]
267 %\end{tcblisting}
268 %
269 %To view the turkey from behind:
270 %\begin{tcblisting}{title={Back view}}
271 %\turkey[back]
272 %\end{tcblisting}
273 %
274 %The key \saminline|3D| will make the turkey 3-dimensional:
275 %\begin{tcblisting}{title={3D view}}
276 %\turkey[3D]
277 %\end{tcblisting}
278 %
279 %And finally the \saminline|contour| key will only draw the outlines:
280 %\begin{tcblisting}{title={Contours}}
281 %\turkey[contour=black]
282 %\end{tcblisting}