Debian Codegraph @

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

raw
1 % !TeX root = ./examples/owl.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-owls}[2025/12/11 version v2.5 Draw owls in TikZ]
16
17 \RequirePackage{tikz}
18 \RequirePackage{tikzlings-addons}
19
20 \newcommand*{\owl}[1][]{%
21 \begin{scope}%
22 \tikzset{/owl/.cd,#1}%
23 \owl@draw%
24 \end{scope}%
25 \thing[#1]%
26 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27 \UseHook{tikzlings/owl/foreground}
28 \UseHook{tikzlings/foreground}
29 \csname owlhookforeground\endcsname
30 \csname tikzlinghookforeground\endcsname
31 %
32 }
33
34 \newif\ifowl@threeD
35 \newif\ifowl@back
36 \newif\ifowl@contour
37
38 \NewHook{tikzlings/owl/background}
39 \NewHook{tikzlings/owl/belly}
40 \NewHook{tikzlings/owl/body}
41 \NewHook{tikzlings/owl/foreground}
42
43 \tikzset{
44 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 %
46 % Pass unknown keys on to tikz
47 %
48 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 /owl/.search also={/tikz,/pgf,/thing},
50 /owl/.cd,
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 %
53 % body
54 %
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 body/.store in = \owl@body,
57 body = brown!70!black,
58 eyes/.store in = \owl@eyes,
59 eyes = white!90!gray,
60 eye/.forward to = /owl/eyes,
61 pupils/.store in = \owl@pupils,
62 pupils = brown!30!black,
63 pupil/.forward to = /owl/pupils,
64 bill/.store in = \owl@bill,
65 bill = orange,
66 feet/.store in = \owl@feet,
67 feet = orange,
68 foot/.forward to = /owl/feet,
69 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70 %
71 % options
72 %
73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74 3D/.code = \owl@threeDtrue,
75 back/.code = \owl@backtrue,
76 contour/.code = \owl@contourtrue
77 \def\owl@contour{#1},
78 contour/.default = black,
79 outline/.forward to = /owl/contour,
80 }
81
82 \def\owl@draw{%
83 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84 %
85 % minimal bounding box size
86 %
87 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88 \path (-0.73, 0.08) rectangle (0.73, 2.24);
89 %
90 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91 %
92 % store the current scale factor
93 % from https://github.com/samcarter/tikzlings/issues/3#issuecomment-461373494
94 %
95 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 \pgfgettransformentries{\tmpscaleA}{\tmpscaleB}{\tmpscaleC}{\tmpscaleD}{\tmp}{\tmp}%
97 \pgfmathsetmacro{\scalingfactor}{sqrt(abs(\tmpscaleA*\tmpscaleD-\tmpscaleB*\tmpscaleC))*sqrt(abs((\pgf@xx/1cm)*(\pgf@yy/1cm)-(\pgf@xy/1cm)*(\pgf@yx/1cm)))}%
98 \pgfmathsetmacro{\xscalefactor}{\tmpscaleA}
99 \pgfmathsetmacro{\yscalefactor}{\tmpscaleD}
100 %
101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102 %
103 % switch between 2D, 3D and contours, from
104 % https://chat.stackexchange.com/transcript/message/45991801#45991801
105 %
106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107 \ifowl@threeD
108 \def\owl@part@draw[##1]{\shade[ball color=##1]}
109 \else% 3D
110 \ifowl@contour
111 \def\owl@part@draw[##1]{\draw[##1,\owl@contour,fill=white,line width=\scalingfactor*0.4pt]}
112 \else% contour
113 \def\owl@part@draw[##1]{\fill[##1]}
114 \fi% contour
115 \fi% 3D
116 %
117 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
118 %
119 % Body parts
120 %
121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
122 %
123 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124 \UseHook{tikzlings/owl/background}
125 \UseHook{tikzlings/background}
126 \csname owlhookbackground\endcsname
127 \csname tikzlinghookbackground\endcsname
128 %
129 % Arms %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130 \owl@part@draw[\owl@body] (0.575,0.8) ellipse[x radius=0.38, y radius=0.1, rotate=-80];
131 \owl@part@draw[\owl@body] (-0.575,0.8) ellipse[x radius=0.38, y radius=0.1, rotate=80];
132 %
133 % Feet if back %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134 \ifowl@back
135 \owl@part@draw[\owl@feet] (0.175,0.2) ellipse[x radius=0.03, y radius=0.1];
136 \owl@part@draw[\owl@feet] (0.225,0.21) ellipse[x radius=0.03, y radius=0.1, rotate=20];
137 \owl@part@draw[\owl@feet] (0.275,0.23) ellipse[x radius=0.03, y radius=0.1, rotate=40];
138 \owl@part@draw[\owl@feet] (-0.175,0.2) ellipse[x radius=0.03, y radius=0.1];
139 \owl@part@draw[\owl@feet] (-0.225,0.21) ellipse[x radius=0.03, y radius=0.1, rotate=-20];
140 \owl@part@draw[\owl@feet] (-0.275,0.23) ellipse[x radius=0.03, y radius=0.1, rotate=-40];
141 \fi% back
142 %
143 % Body %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
144 \owl@part@draw[\owl@body] (0.595, 0.92) .. controls (0.595, 0.26) and (0.355, 0.18) .. (0, 0.18) .. controls (-0.355, 0.18) and (-0.595, 0.26) .. (-0.595, 0.92) .. controls (-0.605, 1.58) and (-0.335, 2.11) .. (0, 2.11) .. controls (0.335, 2.11) and (0.605, 1.58) .. (0.595, 0.92) -- cycle;
145 %
146 % Ears %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
147 \owl@part@draw[\owl@body] (-0.6361, 1.777) .. controls (-0.6361, 1.777) and (-0.7586, 1.9603) .. (-0.6759, 2.2145) .. controls (-0.3248, 1.912) and (0.3248, 1.912) .. (0.6759, 2.2145) .. controls (0.7586, 1.9603) and (0.6361, 1.777) .. (0.6361, 1.777);
148 %
149 % Belly %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
150 \unless\ifowl@back
151 \owl@part@draw[\owl@body!50!white] (0.425,0.5) .. controls (0.425,0.31) and (0.245,0.27) .. (0,0.27) .. controls (-0.245,0.27) and (-0.425,0.31) .. (-0.425,0.5) .. controls (-0.425,0.81) and (-0.225,0.98) .. (0,0.98) .. controls (0.225,0.98) and (0.425,0.81) .. (0.425,0.5) -- cycle;
152 \fi% back
153 %
154 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
155 \UseHook{tikzlings/owl/belly}
156 \UseHook{tikzlings/belly}
157 \csname owlhookbelly\endcsname
158 \csname tikzlinghookbelly\endcsname
159 %
160 % head %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
161 \owl@part@draw[\owl@body] (0,1.55) ellipse[x radius=0.7, y radius=0.55];
162 %
163 % Eyes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
164 \unless\ifowl@back
165 \ifowl@contour
166 \owl@part@draw[\owl@eyes] (-0.28, 1.6) circle[radius=0.22];
167 \owl@part@draw[\owl@eyes] (0.28, 1.6) circle[radius=0.22];
168 \else% contour
169 \fill[\owl@eyes] (-0.28, 1.6) circle[radius=0.22];
170 \fill[\owl@eyes] (0.28, 1.6) circle[radius=0.22];
171 \fi% contour
172 \owl@part@draw[\owl@pupils] (-0.28, 1.6) circle[radius=0.15];
173 \owl@part@draw[\owl@pupils] (0.28, 1.6) circle[radius=0.15];
174 \owl@part@draw[white] (0.25, 1.64) circle[radius=0.03];
175 \owl@part@draw[white] (-0.31, 1.64) circle[radius=0.03];
176 \fi% back
177 %
178 % Bill %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
179 \unless\ifowl@back
180 \owl@part@draw[\owl@bill] (0, 1.4) -- (-0.1, 1.3) -- (0, 1.15) -- (0.1, 1.3) -- cycle;
181 \fi% back
182 %
183 % Feet %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
184 \unless\ifowl@back
185 \owl@part@draw[\owl@feet] (0.175,0.2) ellipse[x radius=0.03, y radius=0.1];
186 \owl@part@draw[\owl@feet] (0.225,0.21) ellipse[x radius=0.03, y radius=0.1, rotate=20];
187 \owl@part@draw[\owl@feet] (0.275,0.23) ellipse[x radius=0.03, y radius=0.1, rotate=40];
188 \owl@part@draw[\owl@feet] (-0.175,0.2) ellipse[x radius=0.03, y radius=0.1];
189 \owl@part@draw[\owl@feet] (-0.225,0.21) ellipse[x radius=0.03, y radius=0.1, rotate=-20];
190 \owl@part@draw[\owl@feet] (-0.275,0.23) ellipse[x radius=0.03, y radius=0.1, rotate=-40];
191 \fi% back
192 %
193 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
194 \UseHook{tikzlings/owl/body}
195 \UseHook{tikzlings/body}
196 \csname owlhookbody\endcsname
197 \csname tikzlinghookbody\endcsname
198 %
199 }
200
201 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
202 %%
203 %% Documentation
204 %%
205 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
206 %\clearpage
207 %\section[Owl]{Jake, the owl}
208 %
209 %\emph{The owl Jake was inspired by the avatar of one of the world's top TikZperts}
210 %
211 %\subsection{Package name}
212 %
213 %\begin{tcolorbox}[title={Package usage}]
214 %\begin{samcode}
215 %\usepackage{tikzlings-owls}
216 %\end{samcode}
217 %\end{tcolorbox}
218 %
219 %\subsection{Basic Usage}
220 %
221 %\begin{tcblisting}{title={Basic owl}}
222 %\owl
223 %\end{tcblisting}
224 %
225 %\subsection{Options}
226 %
227 %The basic owl can be modified by changing its colour:
228 %\begin{tcblisting}{title={Body colour}}
229 %\owl[body=blue]
230 %\end{tcblisting}
231 %
232 %In addition to the colour of the body, the colour of various body parts can be adjusted:
233 %\begin{tcblisting}{title={Eye colour}}
234 %\owl[eyes=red]
235 %\end{tcblisting}
236 %\begin{tcblisting}{title={Pupil colour}}
237 %\owl[pupils=red]
238 %\end{tcblisting}
239 %\begin{tcblisting}{title={Bill colour}}
240 %\owl[bill=red]
241 %\end{tcblisting}
242 %\begin{tcblisting}{title={Foot colour}}
243 %\owl[feet=red]
244 %\end{tcblisting}
245 %
246 %To view the owl from behind:
247 %\begin{tcblisting}{title={Back view}}
248 %\owl[back]
249 %\end{tcblisting}
250 %
251 %The key \saminline|3D| will make the owl 3-dimensional:
252 %\begin{tcblisting}{title={3D view}}
253 %\owl[3D]
254 %\end{tcblisting}
255 %
256 %And finally the \saminline|contour| key will only draw the outlines:
257 %\begin{tcblisting}{title={Contours}}
258 %\owl[contour=black]
259 %\end{tcblisting}