Debian Codegraph @

texmf-dist/tex/latex/tikzlings/tikzlings-rhinos.sty

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