 % !TeX root = ./examples/bee.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-bees}[2025/12/11 version v2.5 Drawing bees in TikZ]

\RequirePackage{tikz}
\RequirePackage{tikzlings-addons}

\newcommand*{\bee}[1][]{%
  \begin{scope}%
    \tikzset{/bee/.cd,#1}%
    \bee@draw%
  \end{scope}%
  \thing[#1]%
  % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \UseHook{tikzlings/bee/foreground}
  \UseHook{tikzlings/foreground}
  \csname beehookforeground\endcsname
  \csname tikzlinghookforeground\endcsname
  %
}

\newif\ifbee@threeD
\newif\ifbee@back
\newif\ifbee@contour
\newif\ifbee@openmouth

\NewHook{tikzlings/bee/background}
\NewHook{tikzlings/bee/belly}
\NewHook{tikzlings/bee/body}
\NewHook{tikzlings/bee/foreground}

\tikzset{
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % Pass unknown keys on to tikz
  %
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  /bee/.search also={/tikz,/pgf,/thing},
  /bee/.cd,
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % body
  %
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  body/.store in     = \bee@body,
  body               = yellow!70!orange,
  hands/.store in    = \bee@hands,
  hands              = black,
  hand/.forward to   = /bee/hands,
  wings/.store in    = \bee@wings,
  wings              = blue!20!cyan!30!white,
  wing/.forward to   = /bee/wings,
  stripes/.store in  = \bee@stripes,
  stripes            = black,
  stripe/.forward to = /bee/stripes,
  antennas/.store in = \bee@antennas,
  antennas           = black,
  antenna/.forward to = /bee/antennas,
  eyes/.store in     = \bee@eyes,
  eyes               = black,
  eye/.forward to    = /bee/eyes,
  mouth/.store in    = \bee@mouth,
  mouth              = black,
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % options
  %
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  openmouth/.code    = \bee@openmouthtrue,
  open mouth/.forward to = /bee/openmouth,
  3D/.code           = \bee@threeDtrue,
  back/.code         = \bee@backtrue,
  contour/.code      = \bee@contourtrue
                       \def\bee@contour{#1}
                       \def\bee@antennas{#1}
                       \def\bee@mouth{#1},
  contour/.default   = black,
  outline/.forward to = /bee/contour,
}

\def\bee@draw{%
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % minimal bounding box size
  %
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \path (-0.88,0.1) rectangle (0.88, 2.4);
  %
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % 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
  %
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \ifbee@threeD
    \def\bee@part@draw[##1]{\shade[ball color=##1]}
  \else% 3D
    \ifbee@contour
      \def\bee@part@draw[##1]{\draw[##1,\bee@contour,fill=white,line width=\scalingfactor*0.4pt]}
    \else% contour
      \def\bee@part@draw[##1]{\fill[##1]}
    \fi% contour
  \fi% 3D
  %
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % Body parts
  %
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \UseHook{tikzlings/bee/background}
  \UseHook{tikzlings/background}
  \csname beehookbackground\endcsname
  \csname tikzlinghookbackground\endcsname
  %
  \ifbee@back
    %
    % Antenna %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \fill[\bee@antennas,rotate around={15:(-0.175,2.115)}] (-0.2,1.93) rectangle (-0.15,2.3);
    \fill[\bee@antennas,rotate around={-15:(0.175,2.115)}] (0.2,1.93) rectangle (0.15,2.3);
    \bee@part@draw[\bee@antennas] (-0.22,2.30) circle[radius=0.07];
    \bee@part@draw[\bee@antennas] (0.22,2.30) circle[radius=0.07];
  \else% back
    % Wings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \ifbee@contour
      \bee@part@draw[\bee@wings] (0.5,0.8) circle[radius=0.35];
      \bee@part@draw[\bee@wings] (0.45,1.25) circle[radius=0.35];
      \bee@part@draw[\bee@wings] (-0.5,0.8) circle[radius=0.35];
      \bee@part@draw[\bee@wings] (-0.45,1.25) circle[radius=0.35];
    \else% contour
      \fill[\bee@wings] (0.45,1.25) circle[radius=0.35] (0.5,0.8) circle[radius=0.35];
      \fill[\bee@wings] (-0.45,1.25) circle[radius=0.35](-0.5,0.8) circle[radius=0.35];
    \fi% contour
  \fi% back
  %
  % Body %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \bee@part@draw[\bee@body] (0,2.1) to[out=180,in=140,looseness=1.2] (-0.3,1.5) to[out=-110,in=180,looseness=1.2] (0,0.15) to[out=00,in=-65,looseness=1.2] (0.3,1.5) to[out=40,in=0,looseness=1.2] cycle;
  \bee@part@draw[\bee@stripes] (-0.3845, 1.2427).. controls (-0.3978, 1.1967) and (-0.4102, 1.1508) .. (-0.4213, 1.1051).. controls (-0.339, 1.0724) and (-0.1703, 1.05) .. (0.025, 1.05).. controls (0.2024, 1.05) and (0.3578, 1.0685) .. (0.4466, 1.0964).. controls (0.4345, 1.1426) and (0.4206, 1.1889) .. (0.4053, 1.2351).. controls (0.3136, 1.2136) and (0.1774, 1.2) .. (0.025, 1.2).. controls (-0.1445, 1.2) and (-0.2941, 1.2169) .. (-0.3845, 1.2427) -- cycle(-0.4505, 0.9692).. controls (-0.4588, 0.9242) and (-0.4654, 0.88) .. (-0.4704, 0.8366).. controls (-0.4375, 0.7877) and (-0.2284, 0.75) .. (0.025, 0.75).. controls (0.2433, 0.75) and (0.4285, 0.778) .. (0.4966, 0.817).. controls (0.4925, 0.8629) and (0.4858, 0.9099) .. (0.4772, 0.9575).. controls (0.3973, 0.9236) and (0.2251, 0.9) .. (0.025, 0.9).. controls (-0.1973, 0.9) and (-0.3855, 0.929) .. (-0.4505, 0.9692) -- cycle(-0.475, 0.65) -- (-0.475, 0.5798).. controls (-0.4712, 0.5424) and (-0.465, 0.5067) .. (-0.4563, 0.4729).. controls (-0.3973, 0.4309) and (-0.2042, 0.4) .. (0.025, 0.4).. controls (0.2141, 0.4) and (0.3785, 0.421) .. (0.4635, 0.452).. controls (0.4809, 0.5028) and (0.4921, 0.5583) .. (0.4975, 0.6175).. controls (0.43, 0.5782) and (0.2442, 0.55) .. (0.025, 0.55).. controls (-0.2511, 0.55) and (-0.475, 0.5947) .. (-0.475, 0.65) -- cycle(-0.3628, 0.2869).. controls (-0.2871, 0.2009) and (-0.1703, 0.15) .. (-0.0, 0.15).. controls (0.1603, 0.15) and (0.2765, 0.1965) .. (0.3564, 0.2753).. controls (0.2681, 0.2596) and (0.1523, 0.25) .. (0.025, 0.25).. controls (-0.1315, 0.25) and (-0.2711, 0.2644) .. (-0.3628, 0.2869) -- cycle;
  %
  % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \UseHook{tikzlings/bee/belly}
  \UseHook{tikzlings/belly}
  \csname beehookbelly\endcsname
  \csname tikzlinghookbelly\endcsname
  %
  % Show details only from the front %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \ifbee@back
    %
    % Wings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \ifbee@contour
      \bee@part@draw[\bee@wings] (0.5,0.8) circle[radius=0.35];
      \bee@part@draw[\bee@wings] (0.45,1.25) circle[radius=0.35];
      \bee@part@draw[\bee@wings] (-0.5,0.8) circle[radius=0.35];
      \bee@part@draw[\bee@wings] (-0.45,1.25) circle[radius=0.35];
    \else% contour
      \fill[\bee@wings] (0.45,1.25) circle[radius=0.35] (0.5,0.8) circle[radius=0.35];
      \fill[\bee@wings] (-0.45,1.25) circle[radius=0.35](-0.5,0.8) circle[radius=0.35];
    \fi% contour
  \else% back
    %
    % Eyes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \bee@part@draw[\bee@eyes] (-0.15,1.8) circle[radius=0.05];
    \bee@part@draw[\bee@eyes] (0.15,1.8) circle[radius=0.05];
    %
    % Arms %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \bee@part@draw[\bee@hands] (-0.25,0.88) circle[x radius=0.07,y radius=0.2, rotate=25];
    \bee@part@draw[\bee@hands] (0.25,0.88) circle[x radius=0.07,y radius=0.2, rotate=-25];
    %
    % Mouth %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \ifbee@openmouth
      \filldraw[\bee@mouth,line width=\scalingfactor*0.4pt] (0.115, 1.6) arc [start angle=-40, end angle=-140, radius=0.16];
    \else
      \draw[\bee@mouth,line width=\scalingfactor*0.4pt] (0.115, 1.6) arc [start angle=-40, end angle=-140, radius=0.16];
    \fi
    %
    % Antenna %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \fill[\bee@antennas,rotate around={15:(-0.175,2.115)}] (-0.2,1.93) rectangle (-0.15,2.3);
    \fill[\bee@antennas,rotate around={-15:(0.175,2.115)}] (0.2,1.93) rectangle (0.15,2.3);
    \bee@part@draw[\bee@antennas] (-0.22,2.30) circle[radius=0.07];
    \bee@part@draw[\bee@antennas] (0.22,2.30) circle[radius=0.07];
    %
  \fi% back
  %
  % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \UseHook{tikzlings/bee/body}
  \UseHook{tikzlings/body}
  \csname beehookbody\endcsname
  \csname tikzlinghookbody\endcsname
  %
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% Documentation
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\clearpage
%\section[Bee]{Beeing, the bee}
%
%\emph{The bee was kindly contributed by @marmot}
%
%\subsection{Package name}
%
%\begin{tcolorbox}[title={Package usage}]
%\begin{samcode}
%\usepackage{tikzlings-bees}
%\end{samcode}
%\end{tcolorbox}
%
%\subsection{Basic Usage}
%
%\begin{tcblisting}{title={Basic bee}}
%\bee
%\end{tcblisting}
%
%\subsection{Options}
%
%The basic bee can be modified by changing its colour:
%\begin{tcblisting}{}
%\bee[body=blue]
%\end{tcblisting}
%
%In addition to the colour of the body, the colour of various body parts can be adjusted:
%\begin{tcblisting}{title={Antenna colour}}
%\bee[antennas=red]
%\end{tcblisting}
%\begin{tcblisting}{title={Eye colour}}
%\bee[eyes=red]
%\end{tcblisting}
%\begin{tcblisting}{title={Mouth colour}}
%\bee[mouth=red]
%\end{tcblisting}
%\begin{tcblisting}{title={Wing colour}}
%\bee[wings=red]
%\end{tcblisting}
%\begin{tcblisting}{title={Hand colour}}
%\bee[hands=red]
%\end{tcblisting}
%\begin{tcblisting}{title={Stripe colour}}
%\bee[stripes=red]
%\end{tcblisting}
%
% The bee can open its mouth:
%\begin{tcblisting}{title={Open mouth}}
%\bee[openmouth]
%\end{tcblisting}
%
%To view the bee from behind:
%\begin{tcblisting}{title={back view}}
%\bee[back]
%\end{tcblisting}
%
%The key \saminline|3D| will make the bee 3-dimensional:
%\begin{tcblisting}{title={3D view}}
%\bee[3D]
%\end{tcblisting}
%
%And finally the \saminline|contour| key will only draw the outlines:
%\begin{tcblisting}{title={Contours}}
%\bee[contour=black]
%\end{tcblisting}
