<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"> % !TeX root = ./examples/bug.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-bugs}[2025/03/23 version v2.3 Drawing bugs in TikZ]

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

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

\newif\ifbug@threeD
\newif\ifbug@leftstep
\newif\ifbug@rightstep
\newif\ifbug@back
\newif\ifbug@contour
\newif\ifbug@openmouth

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

\tikzset{
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % Pass unknown keys on to tikz
  %
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  /bug/.search also={/tikz,/pgf,/thing},
  /bug/.cd,
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % body
  %
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  body/.store in     = \bug@body,
  body               = black!90!white,
  arms/.store in     = \bug@arms,
  arms               = red!80!black,
  arm/.forward to    = /bug/arms,
  wings/.store in    = \bug@wings,
  wings              = red!80!black,
  wing/.forward to   = /bug/wings,
  dots/.store in     = \bug@dots,
  dots               = black!90!white,
  dot/.forward to    = /bug/dots,
  antennas/.store in = \bug@antennas,
  antennas           = red!80!black,
  antenna/.forward to = /bug/antennas,
  eyes/.store in     = \bug@eyes,
  eyes               = white,
  eye/.forward to    = /bug/eyes,
  pupils/.store in   = \bug@pupils,
  pupils             = black,
  pupil/.forward to  = /bug/pupils,
  mouth/.store in    = \bug@mouth,
  mouth              = red,
  feet/.store in     = \bug@feet,
  feet               = red!80!black,
  foot/.forward to   = /bug/feet,
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % options
  %
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3D/.code           = \bug@threeDtrue,
  leftstep/.code     = \bug@leftsteptrue,
  left step/.forward to = /bug/leftstep,
  rightstep/.code    = \bug@rightsteptrue,
  right step/.forward to = /bug/rightstep,
  openmouth/.code    = \bug@openmouthtrue,
  open mouth/.forward to = /bug/openmouth,
  back/.code         = \bug@backtrue,
  contour/.code      = \bug@contourtrue
                       \def\bug@contour{#1}
                       \def\bug@antennas{#1}
                       \def\bug@mouth{#1},
  contour/.default   = black,
  outline/.forward to = /bug/contour,
}

\def\bug@draw{%
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % minimal bounding box size
  %
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \path (-0.92,0.02) rectangle (0.92, 2.36);
  %
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % 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
  %
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \ifbug@threeD
    \def\bug@part@draw[##1]{\shade[ball color=##1]}
  \else% 3D
    \ifbug@contour
      \def\bug@part@draw[##1]{\draw[##1,\bug@contour,fill=white,line width=\scalingfactor*0.4pt]}
    \else% contour
      \def\bug@part@draw[##1]{\fill[##1]}
    \fi% contour
  \fi% 3D
  %
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % Body parts
  %
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \UseHook{tikzlings/bug/background}
  \UseHook{tikzlings/background}
  \csname bughookbackground\endcsname
  \csname tikzlinghookbackground\endcsname
  %
  \ifbug@back
    %
    % Antenna %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \draw[\bug@antennas,line width=\scalingfactor*0.8pt] (0.1134, 1.911) .. controls (0.0917, 2.0537) and (0.0986, 2.1999) .. (0.1608, 2.2816) .. controls (0.245, 2.3919) and (0.3278, 2.3011) .. (0.3272, 2.2192) .. controls (0.3266, 2.1341) and (0.2237, 2.0423) .. (0.1978, 2.1538);
    \draw[\bug@antennas,line width=\scalingfactor*0.8pt] (-0.1134, 1.911) .. controls (-0.0917, 2.0537) and (-0.0986, 2.1999) .. (-0.1608, 2.2816) .. controls (-0.245, 2.3919) and (-0.3278, 2.3011) .. (-0.3272, 2.2192) .. controls (-0.3266, 2.1341) and (-0.2237, 2.0423) .. (-0.1978, 2.1538);
  \else% back
    %
    % Wings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \bug@part@draw[\bug@wings] (-0.0955, 1.4222) .. controls (-0.2086, 1.6765) and (-0.692, 1.2508) .. (-0.8174, 1.0023) .. controls (-0.9304, 0.7786) and (-0.9533, 0.379) .. (-0.7355, 0.2548) .. controls (-0.5988, 0.1768) and (-0.4043, 0.3269) .. (-0.3054, 0.4494) .. controls (-0.097, 0.7075) and (0.0589, 1.0749) .. (-0.0955, 1.4222) -- cycle;
    \bug@part@draw[\bug@wings] (0.0955, 1.4222) .. controls (0.2086, 1.6765) and (0.692, 1.2508) .. (0.8174, 1.0023) .. controls (0.9304, 0.7786) and (0.9533, 0.379) .. (0.7355, 0.2548) .. controls (0.5988, 0.1768) and (0.4043, 0.3269) .. (0.3054, 0.4494) .. controls (0.097, 0.7075) and (-0.0589, 1.0749) .. (0.0955, 1.4222) -- cycle;
    \ifbug@contour
      \bug@part@draw[\bug@dots] (-0.2,0.85) circle [radius=0.08] (-0.5,0.8) circle [radius=0.08] (-0.8,0.75) circle [radius=0.08] (-0.35,0.6) circle [radius=0.08] (-0.65,0.5) circle [radius=0.08] (-0.3,1.05) circle [radius=0.08] (-0.6,1.1) circle [radius=0.08] (-0.35,1.35) circle [radius=0.08] (0.2,0.85) circle [radius=0.08] (0.5,0.8) circle [radius=0.08] (0.8,0.75) circle [radius=0.08] (0.35,0.6) circle [radius=0.08] (0.65,0.5) circle [radius=0.08] (0.3,1.05) circle [radius=0.08] (0.6,1.1) circle [radius=0.08] (0.35,1.35) circle [radius=0.08];
    \else% contour
      \fill[\bug@dots] (-0.2,0.85) circle [radius=0.08] (-0.5,0.8) circle [radius=0.08] (-0.8,0.75) circle [radius=0.08] (-0.35,0.6) circle [radius=0.08] (-0.65,0.5) circle [radius=0.08] (-0.3,1.05) circle [radius=0.08] (-0.6,1.1) circle [radius=0.08] (-0.35,1.35) circle [radius=0.08] (0.2,0.85) circle [radius=0.08] (0.5,0.8) circle [radius=0.08] (0.8,0.75) circle [radius=0.08] (0.35,0.6) circle [radius=0.08] (0.65,0.5) circle [radius=0.08] (0.3,1.05) circle [radius=0.08] (0.6,1.1) circle [radius=0.08] (0.35,1.35) circle [radius=0.08];
    \fi% contour
  \fi% back
  %
  % Feet %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \ifbug@leftstep
      \bug@part@draw[\bug@feet] (-0.2,0.12) ellipse[x radius=0.18, y radius=0.06];
  \else% step
    \bug@part@draw[\bug@feet] (-0.2,0.1) ellipse[x radius=0.18, y radius=0.06];
  \fi% step
  \ifbug@rightstep
      \bug@part@draw[\bug@feet] (0.2,0.12) ellipse[x radius=0.18, y radius=0.06];
  \else% step
    \bug@part@draw[\bug@feet] (0.2,0.1) ellipse[x radius=0.18, y radius=0.06];
  \fi% step
  %
  % Body %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \bug@part@draw[\bug@body]  ( 0.55, 0.75) .. controls ( 0.55, 0.40) and ( 0.55, 0.08) .. ( 0.00, 0.08) .. controls (-0.55, 0.08) and (-0.55, 0.40) .. (-0.55, 0.75) .. controls (-0.55, 1.13) and (-0.30, 1.44) .. ( 0.00, 1.44) .. controls ( 0.30, 1.44) and ( 0.55, 1.13) .. ( 0.55, 0.75) -- cycle;
  %
  % Head %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \bug@part@draw[\bug@body] (0,1.7) circle [radius=0.37];
  %
  % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \UseHook{tikzlings/bug/belly}
  \UseHook{tikzlings/belly}
  \csname bughookbelly\endcsname
  \csname tikzlinghookbelly\endcsname
  %
  % Show details only from the front %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \ifbug@back
    %
    % Wings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \bug@part@draw[\bug@wings] (-0.0955, 1.4222) .. controls (-0.2086, 1.6765) and (-0.692, 1.2508) .. (-0.8174, 1.0023) .. controls (-0.9304, 0.7786) and (-0.9533, 0.379) .. (-0.7355, 0.2548) .. controls (-0.5988, 0.1768) and (-0.4043, 0.3269) .. (-0.3054, 0.4494) .. controls (-0.097, 0.7075) and (0.0589, 1.0749) .. (-0.0955, 1.4222) -- cycle;
    \bug@part@draw[\bug@wings] (0.0955, 1.4222) .. controls (0.2086, 1.6765) and (0.692, 1.2508) .. (0.8174, 1.0023) .. controls (0.9304, 0.7786) and (0.9533, 0.379) .. (0.7355, 0.2548) .. controls (0.5988, 0.1768) and (0.4043, 0.3269) .. (0.3054, 0.4494) .. controls (0.097, 0.7075) and (-0.0589, 1.0749) .. (0.0955, 1.4222) -- cycle;
    \ifbug@contour
      \bug@part@draw[\bug@dots] (-0.2,0.85) circle [radius=0.08] (-0.5,0.8) circle [radius=0.08] (-0.8,0.75) circle [radius=0.08] (-0.35,0.6) circle [radius=0.08] (-0.65,0.5) circle [radius=0.08] (-0.3,1.05) circle [radius=0.08] (-0.6,1.1) circle [radius=0.08] (-0.35,1.35) circle [radius=0.08] (0.2,0.85) circle [radius=0.08] (0.5,0.8) circle [radius=0.08] (0.8,0.75) circle [radius=0.08] (0.35,0.6) circle [radius=0.08] (0.65,0.5) circle [radius=0.08] (0.3,1.05) circle [radius=0.08] (0.6,1.1) circle [radius=0.08] (0.35,1.35) circle [radius=0.08];
    \else% contour
      \fill[\bug@dots] (-0.2,0.85) circle [radius=0.08] (-0.5,0.8) circle [radius=0.08] (-0.8,0.75) circle [radius=0.08] (-0.35,0.6) circle [radius=0.08] (-0.65,0.5) circle [radius=0.08] (-0.3,1.05) circle [radius=0.08] (-0.6,1.1) circle [radius=0.08] (-0.35,1.35) circle [radius=0.08] (0.2,0.85) circle [radius=0.08] (0.5,0.8) circle [radius=0.08] (0.8,0.75) circle [radius=0.08] (0.35,0.6) circle [radius=0.08] (0.65,0.5) circle [radius=0.08] (0.3,1.05) circle [radius=0.08] (0.6,1.1) circle [radius=0.08] (0.35,1.35) circle [radius=0.08];
    \fi% contour
  \else% back
    %
    % Eyes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \bug@part@draw[\bug@eyes] (0.13,1.75) ellipse[x radius=0.067, y radius=0.085];
    \bug@part@draw[\bug@eyes] (-0.13,1.75) ellipse[x radius=0.067, y radius=0.085];
    \bug@part@draw[\bug@pupils] (0.12,1.73) ellipse[x radius=0.019, y radius=0.029];
    \bug@part@draw[\bug@pupils] (-0.12,1.73) ellipse[x radius=0.019, y radius=0.029];
    %
    % Arms %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \bug@part@draw[\bug@arms] (-0.25,0.88) circle[x radius=0.07,y radius=0.18, rotate=35];
    \bug@part@draw[\bug@arms] (0.25,0.88) circle[x radius=0.07,y radius=0.18, rotate=-35];
    %
    % Mouth %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \ifbug@openmouth
      \filldraw[\bug@mouth,line width=\scalingfactor*0.4pt] (0.115, 1.56) arc [start angle=-40, end angle=-140, radius=0.16];
    \else
      \draw[\bug@mouth,line width=\scalingfactor*0.4pt] (0.115, 1.56) arc [start angle=-40, end angle=-140, radius=0.16];
    \fi
    %
    % Antenna %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \draw[\bug@antennas,line width=\scalingfactor*0.8pt] (0.1134, 1.911) .. controls (0.0917, 2.0537) and (0.0986, 2.1999) .. (0.1608, 2.2816) .. controls (0.245, 2.3919) and (0.3278, 2.3011) .. (0.3272, 2.2192) .. controls (0.3266, 2.1341) and (0.2237, 2.0423) .. (0.1978, 2.1538);
    \draw[\bug@antennas,line width=\scalingfactor*0.8pt] (-0.1134, 1.911) .. controls (-0.0917, 2.0537) and (-0.0986, 2.1999) .. (-0.1608, 2.2816) .. controls (-0.245, 2.3919) and (-0.3278, 2.3011) .. (-0.3272, 2.2192) .. controls (-0.3266, 2.1341) and (-0.2237, 2.0423) .. (-0.1978, 2.1538);
    %
  \fi% back
  %
  % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \UseHook{tikzlings/bug/body}
  \UseHook{tikzlings/body}
  \csname bughookbody\endcsname
  \csname tikzlinghookbody\endcsname
  %
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% Documentation
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\clearpage
%\section[Bug]{Marie, the bug}
%
%\emph{For a French girl who likes ladybugs -- the name comes from the German word for ladybug ``MarienkÃ¤fer''}
%
%\subsection{Package name}
%
%\begin{tcolorbox}[title={Package usage}]
%\begin{samcode}
%\usepackage{tikzlings-bugs}
%\end{samcode}
%\end{tcolorbox}
%
%\subsection{Basic Usage}
%
%\begin{tcblisting}{title={Basic bug}}
%\bug
%\end{tcblisting}
%
%\subsection{Options}
%
%The basic bug can be modified by changing its colour:
%\begin{tcblisting}{title={Body colour}}
%\bug[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}}
%\bug[antennas=blue]
%\end{tcblisting}
%\begin{tcblisting}{title={Eye colour}}
%\bug[eyes=blue]
%\end{tcblisting}
%\begin{tcblisting}{title={Pupil colour}}
%\bug[pupils=blue]
%\end{tcblisting}
%\begin{tcblisting}{title={Mouth colour}}
%\bug[mouth=blue]
%\end{tcblisting}
%\begin{tcblisting}{title={Arm colour}}
%\bug[arms=blue]
%\end{tcblisting}
%\begin{tcblisting}{title={Wing colour}}
%\bug[wings=blue]
%\end{tcblisting}
%\begin{tcblisting}{title={Foot colour}}
%\bug[feet=blue]
%\end{tcblisting}
%
% The bug can open its mouth:
%\begin{tcblisting}{title={Open mouth}}
%\bug[openmouth]
%\end{tcblisting}
%
%And the bug can lift its legs:
%\begin{tcblisting}{title={Walking}}
%\bug[leftstep]
%\bug[rightstep,xshift=2cm]
%\end{tcblisting}
%
%To view the bug from behind:
%\begin{tcblisting}{title={Back view}}
%\bug[back]
%\end{tcblisting}
%
%The key \saminline|3D| will make the bug 3-dimensional:
%\begin{tcblisting}{title={3D view}}
%\bug[3D]
%\end{tcblisting}
%
%And finally the \saminline|contour| key will only draw the outlines:
%\begin{tcblisting}{title={Contours}}
%\bug[contour=black]
%\end{tcblisting}
</pre></body></html>