Debian Codegraph @

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

raw
1 % !TeX root = ./examples/dog.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-dogs}[2025/12/11 version v2.5 Drawing dogs in TikZ]
16
17 \RequirePackage{tikz}
18 \RequirePackage{tikzlings-addons}
19
20 \newcommand*{\dog}[1][]{%
21 \begin{scope}%
22 \tikzset{/dog/.cd,#1}%
23 \dog@draw%
24 \end{scope}%
25 \thing[#1]%
26 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27 \UseHook{tikzlings/dog/foreground}
28 \UseHook{tikzlings/foreground}
29 \csname doghookforeground\endcsname
30 \csname tikzlinghookforeground\endcsname
31 }
32
33 \newif\ifdog@threeD
34 \newif\ifdog@back
35 \newif\ifdog@contour
36
37 \NewHook{tikzlings/dog/background}
38 \NewHook{tikzlings/dog/belly}
39 \NewHook{tikzlings/dog/body}
40 \NewHook{tikzlings/dog/foreground}
41
42 \tikzset{
43 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44 %
45 % Pass unknown keys on to tikz
46 %
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48 /dog/.search also={/tikz,/pgf,/thing},
49 /dog/.cd,
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 %
52 % body
53 %
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 body/.store in = \dog@body,
56 body = brown!90!orange!70!white,
57 eyes/.store in = \dog@eyes,
58 eyes = black!80!white,
59 eye/.forward to = /dog/eyes,
60 paws/.store in = \dog@paws,
61 paws = \dog@body!60!white,
62 paw/.forward to = /dog/paws,
63 nose/.store in = \dog@nose,
64 nose = black!80!white,
65 tail/.store in = \dog@tail,
66 tail = \dog@body!60!white,
67 head/.store in = \dog@head,
68 head = \dog@body!60!white,
69 ears/.store in = \dog@ears,
70 ears = \dog@body,
71 ear/.forward to = /dog/ears,
72 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 %
74 % options
75 %
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 tailpos/.is choice,
78 tailpos/left/.code = \def\dog@tailpos{-1},
79 tailpos/right/.code = \def\dog@tailpos{1},
80 tailpos/.default = right,
81 tailpos = right,
82 3D/.code = \dog@threeDtrue,
83 back/.code = \dog@backtrue,
84 contour/.code = \dog@contourtrue
85 \def\dog@contour{#1}
86 \def\dog@whiskers{#1},
87 contour/.default = black,
88 outline/.forward to = /dog/contour,
89 }
90
91 \def\dog@draw{%
92 %
93 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94 %
95 % minimal bounding box size
96 %
97 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
98 \path (-0.6,0.1) rectangle (0.6, 2.25);
99 \path (0,0.1) rectangle (\dog@tailpos*0.96,0.1); % for the tail
100 %
101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102 %
103 % store the current scale factor
104 % from https://github.com/samcarter/tikzlings/issues/3#issuecomment-461373494
105 %
106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107 \pgfgettransformentries{\tmpscaleA}{\tmpscaleB}{\tmpscaleC}{\tmpscaleD}{\tmp}{\tmp}%
108 \pgfmathsetmacro{\scalingfactor}{sqrt(abs(\tmpscaleA*\tmpscaleD-\tmpscaleB*\tmpscaleC))*sqrt(abs((\pgf@xx/1cm)*(\pgf@yy/1cm)-(\pgf@xy/1cm)*(\pgf@yx/1cm)))}%
109 \pgfmathsetmacro{\xscalefactor}{\tmpscaleA}
110 \pgfmathsetmacro{\yscalefactor}{\tmpscaleD}
111 %
112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113 %
114 % switch between 2D, 3D and contours, from
115 % https://chat.stackexchange.com/transcript/message/45991801#45991801
116 %
117 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
118 \ifdog@threeD
119 \def\dog@part@draw[##1]{\shade[ball color=##1]}
120 \else% 3D
121 \ifdog@contour
122 \def\dog@part@draw[##1]{\draw[##1,\dog@contour,fill=white,line width=\scalingfactor*0.4pt]}
123 \else% contour
124 \def\dog@part@draw[##1]{\fill[##1]}
125 \fi% contour
126 \fi% 3D
127 %
128 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
129 %
130 % Body parts
131 %
132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133 %
134 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135 \UseHook{tikzlings/dog/background}
136 \UseHook{tikzlings/background}
137 \csname doghookbackground\endcsname
138 \csname tikzlinghookbackground\endcsname
139 %
140 % body if back %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141 \unless\ifdog@back
142 %
143 % Tail %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
144 \dog@part@draw[\dog@tail,overlay,xscale=\dog@tailpos] (0.8496, 0.6798).. controls (0.6181, 0.2192) and (-0.0349, 0.2165) .. (-0.0273, 0.4485).. controls (-0.0197, 0.6805) and (0.3442, 0.4836) .. (0.5802, 0.6615).. controls (0.7305, 0.7748) and (0.8744, 1.0345) .. (0.9231, 1.0115).. controls (0.9717, 0.9884) and (0.9263, 0.8323) .. (0.8496, 0.6798) -- cycle;
145 %
146 % Body %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
147 \dog@part@draw[\dog@body] (0.53, 0.89) .. controls (0.53, 0.49) and (0.53, 0.18) .. (0, 0.17) .. controls (-0.53, 0.18) and (-0.53, 0.49) .. (-0.53, 0.89) .. controls (-0.53, 1.29) and (-0.24, 1.61) .. (0, 1.61) .. controls (0.24, 1.61) and (0.53, 1.29) .. (0.53, 0.89) -- cycle;
148 \fi% back
149 %
150 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
151 \UseHook{tikzlings/dog/belly}
152 \UseHook{tikzlings/belly}
153 \csname doghookbelly\endcsname
154 \csname tikzlinghookbelly\endcsname
155 %
156 % Head %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
157 \dog@part@draw[\dog@head] (0.51,1.91) .. controls (0.51,1.73) and (0.2,1.24) .. (0,1.24) .. controls (-0.2,1.24) and (-0.51, 1.73) .. (-0.51,1.91) .. controls(-0.51,2.09) and (-0.28,2.24) .. (0,2.24) .. controls (0.28,2.24) and (0.51,2.09) .. (0.51,1.91) -- cycle;
158 %
159 % Paws %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
160 \dog@part@draw[\dog@paws] (-0.18, 0.40).. controls (-0.18, 0.23) and (-0.15, 0.07) .. (-0.28, 0.08).. controls (-0.42, 0.09) and (-0.39, 0.23) .. (-0.39, 0.40).. controls (-0.39, 0.58) and (-0.34, 0.73) .. (-0.28, 0.73).. controls (-0.22, 0.73) and (-0.18, 0.58) .. (-0.18, 0.40) -- cycle;
161 \dog@part@draw[\dog@paws] (0.18, 0.40).. controls (0.18, 0.23) and (0.15, 0.07) .. (0.28, 0.08).. controls (0.42, 0.09) and (0.39, 0.23) .. (0.39, 0.40).. controls (0.39, 0.58) and (0.34, 0.73) .. (0.28, 0.73).. controls (0.22, 0.73) and (0.18, 0.58) .. (0.18, 0.40) -- cycle;
162 %
163 % Show details only from the front %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
164 \ifdog@back
165 % Body if back
166 \dog@part@draw[\dog@body] (0.53, 0.89) .. controls (0.53, 0.49) and (0.53, 0.18) .. (0, 0.17) .. controls (-0.53, 0.18) and (-0.53, 0.49) .. (-0.53, 0.89) .. controls (-0.53, 1.29) and (-0.24, 1.61) .. (0, 1.61) .. controls (0.24, 1.61) and (0.53, 1.29) .. (0.53, 0.89) -- cycle;
167 %
168 % Tail %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
169 \dog@part@draw[\dog@tail,overlay,xscale=\dog@tailpos] (0.8496, 0.6798).. controls (0.6181, 0.2192) and (-0.0349, 0.2165) .. (-0.0273, 0.4485).. controls (-0.0197, 0.6805) and (0.3442, 0.4836) .. (0.5802, 0.6615).. controls (0.7305, 0.7748) and (0.8744, 1.0345) .. (0.9231, 1.0115).. controls (0.9717, 0.9884) and (0.9263, 0.8323) .. (0.8496, 0.6798) -- cycle;
170 %
171 \else
172 %
173 % Eyes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
174 \dog@part@draw[\dog@eyes] (-0.18, 1.73) circle [radius=0.04];
175 \dog@part@draw[\dog@eyes] (0.18, 1.73) circle [radius=0.04];
176 %
177 % Nose %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
178 \dog@part@draw[\dog@nose] (0.09, 1.50) .. controls (0.09, 1.47) and (0.05, 1.41) .. (0, 1.41) .. controls (-0.05, 1.41) and (-0.09, 1.47) .. (-0.09, 1.50) .. controls (-0.09, 1.53) and (-0.05, 1.56) .. (0, 1.56) .. controls (0.05, 1.56) and (0.09, 1.53) .. (0.09, 1.50) -- cycle;
179 %
180 \fi% back
181 %
182 % Ears %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
183 \dog@part@draw[\dog@ears, rotate=-10] (-0.75,1.7) ellipse [x radius=0.14, y radius=0.4];
184 \dog@part@draw[\dog@ears, rotate=10] (0.75,1.7) ellipse [x radius=0.14, y radius=0.4];
185 %
186 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
187 \UseHook{tikzlings/dog/body}
188 \UseHook{tikzlings/body}
189 \csname doghookbody\endcsname
190 \csname tikzlinghookbody\endcsname
191 }
192
193 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
194 %%
195 %% Documentation
196 %%
197 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
198 %\clearpage
199 %\section[Dog]{Cookie, the dog}
200 %
201 %\emph{A friend asked me about a dog-shaped cookie cutter, so the \tikzlings got to have a dog}
202 %
203 %\subsection{Package name}
204 %
205 %\begin{tcolorbox}[title={Package usage}]
206 %\begin{samcode}
207 %\usepackage{tikzlings-dogs}
208 %\end{samcode}
209 %\end{tcolorbox}
210 %
211 %\subsection{Basic Usage}
212 %
213 %\begin{tcblisting}{title={Basic dog}}
214 %\dog
215 %\end{tcblisting}
216 %
217 %\subsection{Options}
218 %
219 %The basic dog can be modified by changing its colour:
220 %\begin{tcblisting}{title={Body colour}}
221 %\dog[body=blue]
222 %\end{tcblisting}
223 %
224 %In addition to the colour of the body, the colour of various body parts can be adjusted:
225 %\begin{tcblisting}{title={Eye colour}}
226 %\dog[eyes=red]
227 %\end{tcblisting}
228 %\begin{tcblisting}{title={Nose colour}}
229 %\dog[nose=red]
230 %\end{tcblisting}
231 %\begin{tcblisting}{title={Head colour}}
232 %\dog[head=red]
233 %\end{tcblisting}
234 %\begin{tcblisting}{title={Ears colour}}
235 %\dog[ears=red]
236 %\end{tcblisting}
237 %\begin{tcblisting}{title={Paw colour}}
238 %\dog[paws=red]
239 %\end{tcblisting}
240 %\begin{tcblisting}{title={Tail colour}}
241 %\dog[tail=red]
242 %\end{tcblisting}
243 %
244 % The dog can wag its tail:
245 %\begin{tcblisting}{title={Wagging tail}}
246 %\dog[tailpos=left]
247 %\dog[tailpos=right,xshift=2cm]
248 %\end{tcblisting}
249 %
250 %To view the dog from behind:
251 %\begin{tcblisting}{title={Back view}}
252 %\dog[back]
253 %\end{tcblisting}
254 %
255 %The key \saminline|3D| will make the dog 3-dimensional:
256 %\begin{tcblisting}{title={3D view}}
257 %\dog[3D]
258 %\end{tcblisting}
259 %
260 %And finally the \saminline|contour| key will only draw the outlines:
261 %\begin{tcblisting}{title={Contours}}
262 %\dog[contour=black]
263 %\end{tcblisting}