 % !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/11/28 version v2.4 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@baby

\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,
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% 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[##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}
%
%\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}
