% !TeX root = ./examples/pig.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-pigs}[2024/12/12 version v2.1 Drawing pigs in TikZ] \RequirePackage{tikz} \RequirePackage{tikzlings-addons} \definecolor{piglight}{RGB}{247,205,193} \newcommand*{\pig}[1][]{% \begin{scope}% \tikzset{/pig/.cd,#1}% \pig@draw% \end{scope}% \thing[#1]% % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \csname pighookforeground\endcsname \csname tikzlinghookforeground\endcsname % } \newif\ifpig@threeD \newif\ifpig@back \newif\ifpig@contour \tikzset{ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Pass unknown keys on to tikz % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% /pig/.search also={/tikz,/pgf,/thing}, /pig/.cd, %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % body % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% body/.store in = \pig@body, body = piglight, eye/.store in = \pig@eye, eye = gray, tail/.store in = \pig@tail, tail = pig@bodysat22, mouth/.store in = \pig@mouth, mouth = gray, %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % options % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3D/.code = \pig@threeDtrue \def\pig@mouth{gray!70!black}, back/.code = \pig@backtrue, contour/.code = \pig@contourtrue \def\pig@contour{#1} \def\pig@mouth{#1} \def\pig@tail{#1}, contour/.default = black, outline/.forward to = /pig/contour, } \def\pig@draw{% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % minimal bounding box size % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \path (-0.625,0.1) rectangle (0.905, 2.27); % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % 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 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \ifpig@threeD \def\pig@part@draw[##1]{\shade[ball color=##1]} \else% 3D \ifpig@contour \def\pig@part@draw[##1]{\draw[##1,\pig@contour,fill=white,line width=\scalingfactor*0.4pt]} \else% contour \def\pig@part@draw[##1]{\fill[##1]} \fi% contour \fi% 3D % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % generating saturated version of body colour % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \extractcolorspecs{\pig@body}{\pig@model}{\pig@colorspec} \convertcolorspec{\pig@model}{\pig@colorspec}{hsb}{\pig@hsbcolorspec} \pgfmathsetmacro{\pig@hue}{(array({\pig@hsbcolorspec},0))} \pgfmathsetmacro{\pig@sat}{(array({\pig@hsbcolorspec},1)+0.22)} \pgfmathsetmacro{\pig@bright}{(array({\pig@hsbcolorspec},2))} \definecolor{pig@bodysat22}{hsb}{\pig@hue,\pig@sat,\pig@bright} % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Body parts % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \csname pighookbackground\endcsname \csname tikzlinghookbackground\endcsname % % Tail %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \unless\ifpig@back \draw[\pig@tail,line width=\scalingfactor*0.8pt] (0.8431, 0.583) .. controls (0.8609, 0.4063) and (0.7006, 0.361) .. (0.6384, 0.4293) .. controls (0.5762, 0.4976) and (0.5613, 0.6052) .. (0.6551, 0.629) .. controls (0.7537, 0.6541) and (0.7759, 0.5628) .. (0.7455, 0.4948) .. controls (0.6412, 0.2697) and (0.3543, 0.356) .. (0.2638, 0.4238) .. controls (0.1967, 0.4779) and (0.1788, 0.6076) .. (0.3192, 0.633) .. controls (0.6000, 0.6836) and (0.5130, 0.3048) .. (0.2098, 0.3322) .. controls (0.0809, 0.3438) and (0.0809, 0.5236) .. (0.0809, 0.5236); \fi% back % % Feet if back %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \ifpig@back \pig@part@draw[pig@bodysat22] (0.3216,0.15) arc (-15:195:0.12) -- (0.16,0.15) to [bend left] (0.25,0.15) -- cycle; \pig@part@draw[pig@bodysat22] (-0.3216,0.15) arc (195:-15:0.12) -- (-0.16,0.15) to[bend right] (-0.25,0.15) --cycle; \fi% back % % Body %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \pig@part@draw[\pig@body] ( 0.6, 0.8 ) .. controls ( 0.6 , 0.4) and ( 0.35, 0.16) .. ( 0.0, 0.16) .. controls (-0.35, 0.16) and (-0.6 , 0.4) .. (-0.6, 0.8 ) .. controls (-0.6 , 1.3) and (-0.35, 1.5) .. ( 0.0, 1.5) .. controls ( 0.35, 1.5) and ( 0.6 , 1.3) .. ( 0.6, 0.75) -- cycle; % % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \csname pighookbelly\endcsname \csname tikzlinghookbelly\endcsname % % Arms %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \unless\ifpig@back \pig@part@draw[pig@bodysat22] (-0.2402, 0.9823) .. controls (-0.2994, 1.0582) and (-0.3721, 1.0651) .. (-0.4024, 0.9978) .. controls (-0.4327, 0.9305) and (-0.4092, 0.8145) .. (-0.35, 0.7386) .. controls (-0.3311, 0.7145) and (-0.3101, 0.6964) .. (-0.289, 0.6862) .. controls (-0.2755, 0.7023) and (-0.2498, 0.7563) .. (-0.2498, 0.7563) .. controls (-0.2498, 0.7563) and (-0.1790, 0.731) .. (-0.1611, 0.746) .. controls (-0.1611, 0.746) and (-0.1809, 0.9064) .. (-0.2402, 0.9823) -- cycle; \pig@part@draw[pig@bodysat22] (0.2402, 0.9823) .. controls (0.2994, 1.0582) and (0.3721, 1.0651) .. (0.4024, 0.9978) .. controls (0.4327, 0.9305) and (0.4092, 0.8145) .. (0.35, 0.7386) .. controls (0.3311, 0.7145) and (0.3101, 0.6964) .. (0.289, 0.6862) .. controls (0.2755, 0.7023) and (0.2498, 0.7563) .. (0.2498, 0.7563) .. controls (0.2498, 0.7563) and (0.1790, 0.731) .. (0.1611, 0.746) .. controls (0.1611, 0.746) and (0.1809, 0.9064) .. (0.2402, 0.9823) -- cycle; \fi% back % % Head %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \pig@part@draw[\pig@body] (0,1.64) ellipse[x radius=.5, y radius=.5]; % % Show details only from the front %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \unless\ifpig@back % % Eyes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \pig@part@draw[\pig@eye] (-0.09, 1.82) circle[radius=0.02]; \pig@part@draw[\pig@eye] ( 0.09, 1.82) circle[radius=0.02]; % % Nose %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \pig@part@draw[pig@bodysat22] (0, 1.62) ellipse[x radius=0.18, y radius=0.14]; \pig@part@draw[gray] (-0.06, 1.62) circle[radius=0.035]; \pig@part@draw[gray] ( 0.06, 1.62) circle[radius=0.035]; % % Mouth %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \draw[\pig@mouth,line width=\scalingfactor*0.4pt] (0.105, 1.46) arc [start angle=-50, end angle=-130, radius=0.16] ; % % Feet %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \pig@part@draw[pig@bodysat22] (0.3216,0.15) arc (-15:195:0.12) -- (0.16,0.15) to [bend left] (0.25,0.15) -- cycle; \pig@part@draw[pig@bodysat22] (-0.3216,0.15) arc (195:-15:0.12) -- (-0.16,0.15) to[bend right] (-0.25,0.15) --cycle; % \fi% back % % Ears %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \pig@part@draw[pig@bodysat22] (0.22, 2.0392) .. controls (0.22, 2.1584) and (0.49460, 2.255) .. (0.49460, 2.255) .. controls (0.49460, 2.255) and (0.5300, 1.86) .. (0.3721, 1.86) .. controls (0.2891, 1.86) and (0.22, 1.9201) .. (0.22, 2.0392) -- cycle; \pig@part@draw[\pig@body] (0.22, 2.0392) .. controls (0.26, 2.1584) and (0.47, 2.22) .. (0.47, 2.20) .. controls (0.47, 2.2) and (0.49, 1.9) .. (0.3721, 1.9) .. controls (0.2891, 1.88) and (0.22, 1.88) .. (0.22, 2.0392) -- cycle; \pig@part@draw[pig@bodysat22] (-0.22, 2.0392) .. controls (-0.22, 2.1584) and (-0.49460, 2.255) .. (-0.49460, 2.255) .. controls (-0.49460, 2.255) and (-0.5300, 1.86) .. (-0.3721, 1.86) .. controls (-0.2891, 1.86) and (-0.22, 1.9201) .. (-0.22, 2.0392) -- cycle; \pig@part@draw[\pig@body] (-0.22, 2.0392) .. controls (-0.26, 2.1584) and (-0.47, 2.22) .. (-0.47, 2.20) .. controls (-0.47, 2.2) and (-0.49, 1.9) .. (-0.3721, 1.9) .. controls (-0.2891, 1.88) and (-0.22, 1.88) .. (-0.22, 2.0392) -- cycle; % % Tail if back %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \ifpig@back \draw[\pig@tail,line width=\scalingfactor*0.8pt] (0.8431, 0.583) .. controls (0.8609, 0.4063) and (0.7006, 0.361) .. (0.6384, 0.4293) .. controls (0.5762, 0.4976) and (0.5613, 0.6052) .. (0.6551, 0.629) .. controls (0.7537, 0.6541) and (0.7759, 0.5628) .. (0.7455, 0.4948) .. controls (0.6412, 0.2697) and (0.3543, 0.356) .. (0.2638, 0.4238) .. controls (0.1967, 0.4779) and (0.1788, 0.6076) .. (0.3192, 0.633) .. controls (0.6000, 0.6836) and (0.5130, 0.3048) .. (0.2098, 0.3322) .. controls (0.0809, 0.3438) and (0.0809, 0.5236) .. (0.0809, 0.5236); \fi% back % % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \csname pighookbody\endcsname \csname tikzlinghookbody\endcsname % } %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% %% Documentation %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\clearpage %\section[Pig]{Ms Piggy, the pig} % %\emph{Added on February 5th, 2019 to commemorate the Chinese year of the pig} % %\subsection{Package name} % %\begin{tcolorbox}[title={Package usage}] %\begin{samcode} %\usepackage{tikzlings-pigs} %\end{samcode} %\end{tcolorbox} % %\subsection{Basic Usage} % %\begin{tcblisting}{title={Basic pig}} %\pig %\end{tcblisting} % %\subsection{Options} % %The basic pig can be modified by changing its colour: %\begin{tcblisting}{title={Body colour}} %\pig[body=blue] %\end{tcblisting} % %In addition to the colour of the body, the colour of various body parts can be adjusted: %\begin{tcblisting}{title={Eye colour}} %\pig[eye=red] %\end{tcblisting} %\begin{tcblisting}{title={Tail colour}} %\pig[tail=red] %\end{tcblisting} %\begin{tcblisting}{title={Mouth colour}} %\pig[mouth=red] %\end{tcblisting} % %To view the pig from behind: %\begin{tcblisting}{title={Back view}} %\pig[back] %\end{tcblisting} % %The key \saminline|3D| will make the pig 3-dimensional: %\begin{tcblisting}{title={3D view}} %\pig[3D] %\end{tcblisting} % %And finally the \saminline|contour| key will only draw the outlines: %\begin{tcblisting}{title={Contours}} %\pig[contour=black] %\end{tcblisting}