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