| 1 |
% !TeX root = ./examples/hippo.tex |
| 2 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 |
%% |
| 4 |
%% This package is part of the TikZlings package |
| 5 |
%% A package to bring cute little animals and other beings into tikz |
| 6 |
%% Maintained by samcarter |
| 7 |
%% |
| 8 |
%% Project repository and bug tracker: |
| 9 |
%% https://github.com/samcarter/tikzlings |
| 10 |
%% |
| 11 |
%% Released under the LaTeX Project Public License v1.3c or later |
| 12 |
%% See https://www.latex-project.org/lppl.txt |
| 13 |
%% |
| 14 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 15 |
\ProvidesPackage{tikzlings-hippos}[2025/12/11 version v2.5 Drawing hippos in TikZ] |
| 16 |
|
| 17 |
\RequirePackage{tikz} |
| 18 |
\RequirePackage{tikzlings-addons} |
| 19 |
|
| 20 |
\newcommand*{\hippo}[1][]{% |
| 21 |
\begin{scope}% |
| 22 |
\tikzset{/hippo/.cd,#1}% |
| 23 |
\hippo@draw% |
| 24 |
\end{scope}% |
| 25 |
\thing[#1]% |
| 26 |
% adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 27 |
\UseHook{tikzlings/hippo/foreground} |
| 28 |
\UseHook{tikzlings/foreground} |
| 29 |
\csname hippohookforeground\endcsname |
| 30 |
\csname tikzlinghookforeground\endcsname |
| 31 |
} |
| 32 |
|
| 33 |
\newif\ifhippo@threeD |
| 34 |
\newif\ifhippo@back |
| 35 |
\newif\ifhippo@contour |
| 36 |
\newif\ifhippo@openmouth |
| 37 |
|
| 38 |
\NewHook{tikzlings/hippo/background} |
| 39 |
\NewHook{tikzlings/hippo/belly} |
| 40 |
\NewHook{tikzlings/hippo/body} |
| 41 |
\NewHook{tikzlings/hippo/foreground} |
| 42 |
|
| 43 |
\tikzset{ |
| 44 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 45 |
% |
| 46 |
% Pass unknown keys on to tikz |
| 47 |
% |
| 48 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 49 |
/hippo/.search also={/tikz,/pgf,/thing}, |
| 50 |
/hippo/.cd, |
| 51 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 52 |
% |
| 53 |
% body |
| 54 |
% |
| 55 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 56 |
body/.store in = \hippo@body, |
| 57 |
body = gray!55!white, |
| 58 |
eyes/.store in = \hippo@eyes, |
| 59 |
eyes = white, |
| 60 |
eye/.forward to = /hippo/eyes, |
| 61 |
pupils/.store in = \hippo@pupils, |
| 62 |
pupils = black, |
| 63 |
pupil/.forward to = /hippo/pupils, |
| 64 |
toes/.store in = \hippo@toes, |
| 65 |
toes = \hippo@body, |
| 66 |
toe/.forward to = /hippo/toes, |
| 67 |
mouth/.store in = \hippo@mouth, |
| 68 |
mouth = \hippo@body!50!black, |
| 69 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 70 |
% |
| 71 |
% options |
| 72 |
% |
| 73 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 74 |
openmouth/.code = \hippo@openmouthtrue, |
| 75 |
open mouth/.forward to = /hippo/openmouth, |
| 76 |
3D/.code = \hippo@threeDtrue |
| 77 |
\def\hippo@mouth{black}, |
| 78 |
back/.code = \hippo@backtrue, |
| 79 |
contour/.code = \hippo@contourtrue |
| 80 |
\def\hippo@contour{#1} |
| 81 |
\def\hippo@mouth{#1}, |
| 82 |
contour/.default = black, |
| 83 |
outline/.forward to = /hippo/contour, |
| 84 |
} |
| 85 |
|
| 86 |
\def\hippo@draw{% |
| 87 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 88 |
% |
| 89 |
% minimal bounding box size |
| 90 |
% |
| 91 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 92 |
\path (-0.625,0.1) rectangle (0.625, 2.17); |
| 93 |
% |
| 94 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 95 |
% |
| 96 |
% store the current scale factor |
| 97 |
% from https://github.com/samcarter/tikzlings/issues/3#issuecomment-461373494 |
| 98 |
% |
| 99 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 100 |
\pgfgettransformentries{\tmpscaleA}{\tmpscaleB}{\tmpscaleC}{\tmpscaleD}{\tmp}{\tmp}% |
| 101 |
\pgfmathsetmacro{\scalingfactor}{sqrt(abs(\tmpscaleA*\tmpscaleD-\tmpscaleB*\tmpscaleC))*sqrt(abs((\pgf@xx/1cm)*(\pgf@yy/1cm)-(\pgf@xy/1cm)*(\pgf@yx/1cm)))}% |
| 102 |
\pgfmathsetmacro{\xscalefactor}{\tmpscaleA} |
| 103 |
\pgfmathsetmacro{\yscalefactor}{\tmpscaleD} |
| 104 |
% |
| 105 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 106 |
% |
| 107 |
% switch between 2D, 3D and contours, from |
| 108 |
% https://chat.stackexchange.com/transcript/message/45991801#45991801 |
| 109 |
% |
| 110 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 111 |
\ifhippo@threeD |
| 112 |
\def\hippo@part@draw[##1]{\shade[ball color=##1]} |
| 113 |
\else% 3D |
| 114 |
\ifhippo@contour |
| 115 |
\def\hippo@part@draw[##1]{\draw[##1,\hippo@contour,fill=white,line width=\scalingfactor*0.4pt]} |
| 116 |
\else% contour |
| 117 |
\def\hippo@part@draw[##1]{\fill[##1]} |
| 118 |
\fi% contour |
| 119 |
\fi% 3D |
| 120 |
% |
| 121 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 122 |
% |
| 123 |
% Body parts |
| 124 |
% |
| 125 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 126 |
% |
| 127 |
% adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 128 |
\UseHook{tikzlings/hippo/background} |
| 129 |
\UseHook{tikzlings/background} |
| 130 |
\csname hippohookbackground\endcsname |
| 131 |
\csname tikzlinghookbackground\endcsname |
| 132 |
% |
| 133 |
% Ears %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 134 |
\hippo@part@draw[\hippo@body!70!black] (0.23,2.03) ellipse[x radius=0.09, y radius=0.13, rotate=-30]; |
| 135 |
\hippo@part@draw[\hippo@body!70!black] (-0.23,2.03) ellipse[x radius=0.09, y radius=0.13, rotate=30]; |
| 136 |
% |
| 137 |
% Feet if back %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 138 |
\ifhippo@back |
| 139 |
\hippo@part@draw[\hippo@body!70!black] (-0.08,0.13) arc [start angle=0, end angle=180, x radius=0.17, y radius=0.19] -- cycle; |
| 140 |
\hippo@part@draw[\hippo@body!70!black](0.08,0.13) arc [start angle=180, end angle=0, x radius=0.17, y radius=0.19] -- cycle; |
| 141 |
\fi% back |
| 142 |
% |
| 143 |
% Nose if back %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 144 |
\ifhippo@back |
| 145 |
\hippo@part@draw[\hippo@body!85!black] (0, 1.55) ellipse[x radius=0.42, y radius=0.2]; |
| 146 |
\fi% back |
| 147 |
% |
| 148 |
% Body %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 149 |
\hippo@part@draw[\hippo@body] ( 0.6, 0.8 ) .. controls ( 0.6 , 0.4) and ( 0.35, 0.19) .. ( 0.0, 0.19) .. controls (-0.35, 0.19) and (-0.6 , 0.4) .. (-0.6, 0.8 ) .. controls (-0.6 , 1.3) and (-0.35, 1.65) .. ( 0.0, 1.65) .. controls ( 0.35, 1.65) and ( 0.6 , 1.3) .. ( 0.6, 0.8) -- cycle; |
| 150 |
% |
| 151 |
% adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 152 |
\UseHook{tikzlings/hippo/belly} |
| 153 |
\UseHook{tikzlings/belly} |
| 154 |
\csname hippohookbelly\endcsname |
| 155 |
\csname tikzlinghookbelly\endcsname |
| 156 |
% |
| 157 |
% Arms %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 158 |
\unless\ifhippo@back |
| 159 |
\hippo@part@draw[\hippo@body!70!black] (0.35,1.0) ellipse[x radius=0.24, y radius=0.13, rotate=90]; |
| 160 |
\hippo@part@draw[\hippo@body!70!black] (-0.35,1.0) ellipse[x radius=0.24, y radius=0.13, rotate=-90]; |
| 161 |
\fi% back |
| 162 |
% |
| 163 |
% Head %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 164 |
\hippo@part@draw[\hippo@body] (0, 1.76) circle[radius=0.36]; |
| 165 |
% |
| 166 |
% Show details only from the front %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 167 |
\unless\ifhippo@back |
| 168 |
% |
| 169 |
% Eyes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 170 |
\ifhippo@contour |
| 171 |
\hippo@part@draw[\hippo@eyes] (-0.11, 1.83) ellipse[x radius=0.08, y radius=0.12]; |
| 172 |
\hippo@part@draw[\hippo@eyes] (0.11, 1.83) ellipse[x radius=0.08, y radius=0.12]; |
| 173 |
\hippo@part@draw[\hippo@pupils] (-0.105, 1.78) ellipse[x radius=0.04, y radius=0.07]; |
| 174 |
\hippo@part@draw[\hippo@pupils] (0.105, 1.78) ellipse[x radius=0.04, y radius=0.07]; |
| 175 |
\else% contour |
| 176 |
\fill[\hippo@eyes] (-0.11, 1.83) ellipse[x radius=0.08, y radius=0.12]; |
| 177 |
\fill[\hippo@eyes] (0.11, 1.83) ellipse[x radius=0.08, y radius=0.12]; |
| 178 |
\fill[\hippo@pupils] (-0.105, 1.78) ellipse[x radius=0.04, y radius=0.07]; |
| 179 |
\fill[\hippo@pupils] (0.105, 1.78) ellipse[x radius=0.04, y radius=0.07]; |
| 180 |
\fi% contour |
| 181 |
% |
| 182 |
% Nose %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 183 |
\hippo@part@draw[\hippo@body!85!black] (0, 1.55) ellipse[x radius=0.42, y radius=0.2]; |
| 184 |
\hippo@part@draw[\hippo@mouth] (-0.07, 1.63) circle[radius=0.035]; |
| 185 |
\hippo@part@draw[\hippo@mouth] (0.07, 1.63) circle[radius=0.035]; |
| 186 |
% |
| 187 |
% Mouth %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 188 |
\ifhippo@openmouth |
| 189 |
\filldraw[\hippo@mouth,line width=\scalingfactor*0.4pt] (0.125, 1.5) arc [start angle=-50, end angle=-130, radius=0.2]; |
| 190 |
\else% open mouth |
| 191 |
\draw[\hippo@mouth,line width=\scalingfactor*0.4pt] (0.125, 1.5) arc [start angle=-50, end angle=-130, radius=0.2]; |
| 192 |
\fi% open mouth |
| 193 |
% |
| 194 |
% Feet %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 195 |
\hippo@part@draw[\hippo@body!70!black] (-0.08,0.13) arc [start angle=0, end angle=180, x radius=0.17, y radius=0.19] -- cycle; |
| 196 |
\hippo@part@draw[\hippo@body!70!black](0.08,0.13) arc [start angle=180, end angle=0, x radius=0.17, y radius=0.19] -- cycle; |
| 197 |
\hippo@part@draw[\hippo@toes] (-0.08,0.13) arc [start angle=0, end angle=180, x radius=0.05, y radius=0.08] -- cycle; |
| 198 |
\hippo@part@draw[\hippo@toes] (-0.2,0.13) arc [start angle=0, end angle=180, x radius=0.05, y radius=0.1] -- cycle; |
| 199 |
\hippo@part@draw[\hippo@toes] (-0.32,0.13) arc [start angle=0, end angle=180, x radius=0.05, y radius=0.08] -- cycle; |
| 200 |
\hippo@part@draw[\hippo@toes] (0.08,0.13) arc [start angle=180, end angle=0, x radius=0.05, y radius=0.08] -- cycle; |
| 201 |
\hippo@part@draw[\hippo@toes] (0.2,0.13) arc [start angle=180, end angle=0, x radius=0.05, y radius=0.1] -- cycle; |
| 202 |
\hippo@part@draw[\hippo@toes] (0.32,0.13) arc [start angle=180, end angle=0, x radius=0.05, y radius=0.08] -- cycle; |
| 203 |
% |
| 204 |
\fi% back |
| 205 |
% |
| 206 |
% adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 207 |
\UseHook{tikzlings/hippo/body} |
| 208 |
\UseHook{tikzlings/body} |
| 209 |
\csname hippohookbody\endcsname |
| 210 |
\csname tikzlinghookbody\endcsname |
| 211 |
% |
| 212 |
} |
| 213 |
|
| 214 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 215 |
%% |
| 216 |
%% Documentation |
| 217 |
%% |
| 218 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 219 |
%\clearpage |
| 220 |
%\section[Hippo]{Sieglinde, the hippo} |
| 221 |
% |
| 222 |
%\emph{For the winner of the 2019 Groundhog Challenge} |
| 223 |
% |
| 224 |
%\subsection{Package name} |
| 225 |
% |
| 226 |
%\begin{tcolorbox}[title={Package usage}] |
| 227 |
%\begin{samcode} |
| 228 |
%\usepackage{tikzlings-hippos} |
| 229 |
%\end{samcode} |
| 230 |
%\end{tcolorbox} |
| 231 |
% |
| 232 |
%\subsection{Basic Usage} |
| 233 |
% |
| 234 |
%\begin{tcblisting}{title={Basic hippo}} |
| 235 |
%\hippo |
| 236 |
%\end{tcblisting} |
| 237 |
% |
| 238 |
%\subsection{Options} |
| 239 |
% |
| 240 |
%The basic hippo can be modified by changing its colour: |
| 241 |
%\begin{tcblisting}{title={Body colour}} |
| 242 |
%\hippo[body=blue] |
| 243 |
%\end{tcblisting} |
| 244 |
% |
| 245 |
%In addition to the colour of the body, the colour of various body parts can be adjusted: |
| 246 |
%\begin{tcblisting}{title={Eye colour}} |
| 247 |
%\hippo[eyes=red] |
| 248 |
%\end{tcblisting} |
| 249 |
%\begin{tcblisting}{title={Pupil colour}} |
| 250 |
%\hippo[pupils=red] |
| 251 |
%\end{tcblisting} |
| 252 |
%\begin{tcblisting}{title={Mouth colour}} |
| 253 |
%\hippo[mouth=red] |
| 254 |
%\end{tcblisting} |
| 255 |
% |
| 256 |
% The hippo can open its mouth: |
| 257 |
%\begin{tcblisting}{title={Open mouth}} |
| 258 |
%\hippo[openmouth] |
| 259 |
%\end{tcblisting} |
| 260 |
% |
| 261 |
%The hippo can also do its nails: |
| 262 |
%\begin{tcblisting}{title={Toe colour}} |
| 263 |
%\hippo[toes=red] |
| 264 |
%\end{tcblisting} |
| 265 |
% |
| 266 |
%To view the hippo from behind: |
| 267 |
%\begin{tcblisting}{title={Back view}} |
| 268 |
%\hippo[back] |
| 269 |
%\end{tcblisting} |
| 270 |
% |
| 271 |
%The key \saminline|3D| will make the hippo 3-dimensional: |
| 272 |
%\begin{tcblisting}{title={3D view}} |
| 273 |
%\hippo[3D] |
| 274 |
%\end{tcblisting} |
| 275 |
% |
| 276 |
%And finally the \saminline|contour| key will only draw the outlines: |
| 277 |
%\begin{tcblisting}{title={Contours}} |
| 278 |
%\hippo[contour=black] |
| 279 |
%\end{tcblisting} |