Debian Codegraph @

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

raw
1 % !TeX root = ./examples/mouse.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-mice}[2025/12/11 version v2.5 Drawing mice in TikZ]
16
17 \RequirePackage{tikz}
18 \RequirePackage{tikzlings-addons}
19
20 \newcommand*{\mouse}[1][]{%
21 \begin{scope}%
22 \tikzset{/mouse/.cd,#1}%
23 \mouse@draw%
24 \end{scope}%
25 \thing[#1]%
26 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27 \UseHook{tikzlings/mouse/foreground}
28 \UseHook{tikzlings/foreground}
29 \csname mousehookforeground\endcsname
30 \csname tikzlinghookforeground\endcsname
31 %
32 }
33
34 \newif\ifmouse@threeD
35 \newif\ifmouse@rotatearms
36 \newif\ifmouse@leftstep
37 \newif\ifmouse@rightstep
38 \newif\ifmouse@back
39 \newif\ifmouse@contour
40
41 \NewHook{tikzlings/mouse/background}
42 \NewHook{tikzlings/mouse/belly}
43 \NewHook{tikzlings/mouse/body}
44 \NewHook{tikzlings/mouse/foreground}
45
46 \tikzset{
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48 %
49 % Pass unknown keys on to tikz
50 %
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 /mouse/.search also={/tikz,/pgf,/thing},
53 /mouse/.cd,
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 %
56 % body
57 %
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59 body/.store in = \mouse@body,
60 body = gray!90!white,
61 eyes/.store in = \mouse@eyes,
62 eyes = \mouse@body!50!black,
63 eye/.forward to = /mouse/eyes,
64 whiskers/.store in = \mouse@whiskers,
65 whiskers = \mouse@body!50!black,
66 whisker/.forward to = /mouse/whiskers,
67 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68 %
69 % options
70 %
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 3D/.code = \mouse@threeDtrue,
73 rotatearms/.code = \mouse@rotatearmstrue
74 \def\mouse@rotatearms{#1},
75 rotate arms/.forward to = /mouse/rotatearms,
76 rotate arm/.forward to = /mouse/rotatearms,
77 rotatearms = 20,
78 leftstep/.code = \mouse@leftsteptrue,
79 left step/.forward to = /mouse/leftstep,
80 rightstep/.code = \mouse@rightsteptrue,
81 right step/.forward to = /mouse/rightstep,
82 back/.code = \mouse@backtrue,
83 contour/.code = \mouse@contourtrue
84 \def\mouse@contour{#1}
85 \def\mouse@whiskers{#1},
86 contour/.default = black,
87 outline/.forward to = /mouse/contour,
88 }
89
90 \def\mouse@draw{%
91 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92 %
93 % minimal bounding box size
94 %
95 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 \path (-0.625,0.1) rectangle (0.905, 2.17);
97 %
98 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99 %
100 % store the current scale factor
101 % from https://github.com/samcarter/tikzlings/issues/3#issuecomment-461373494
102 %
103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104 \pgfgettransformentries{\tmpscaleA}{\tmpscaleB}{\tmpscaleC}{\tmpscaleD}{\tmp}{\tmp}%
105 \pgfmathsetmacro{\scalingfactor}{sqrt(abs(\tmpscaleA*\tmpscaleD-\tmpscaleB*\tmpscaleC))*sqrt(abs((\pgf@xx/1cm)*(\pgf@yy/1cm)-(\pgf@xy/1cm)*(\pgf@yx/1cm)))}%
106 \pgfmathsetmacro{\xscalefactor}{\tmpscaleA}
107 \pgfmathsetmacro{\yscalefactor}{\tmpscaleD}
108 %
109 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
110 %
111 % switch between 2D, 3D and contours, from
112 % https://chat.stackexchange.com/transcript/message/45991801#45991801
113 %
114 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115 \ifmouse@threeD
116 \def\mouse@part@draw[##1]{\shade[ball color=##1]}
117 \else% 3D
118 \ifmouse@contour
119 \def\mouse@part@draw[##1]{\draw[##1,\mouse@contour,fill=white,line width=\scalingfactor*0.4pt]}
120 \else% contour
121 \def\mouse@part@draw[##1]{\fill[##1]}
122 \fi% contour
123 \fi% 3D
124 %
125 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
126 %
127 % Body parts
128 %
129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130 %
131 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
132 \UseHook{tikzlings/mouse/background}
133 \UseHook{tikzlings/background}
134 \csname mousehookbackground\endcsname
135 \csname tikzlinghookbackground\endcsname
136 %
137 % Feet %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
138 \ifmouse@leftstep
139 \mouse@part@draw[\mouse@body!65!white] (-0.255,0.25) ellipse[x radius=0.23, y radius=0.09];
140 \else% step
141 \mouse@part@draw[\mouse@body!65!white] (-0.255,0.2) ellipse[x radius=0.23, y radius=0.09];
142 \fi% step
143 %
144 \ifmouse@rightstep
145 \mouse@part@draw[\mouse@body!65!white] (0.255,0.25) ellipse[x radius=0.23, y radius=0.09];
146 \else% step
147 \mouse@part@draw[\mouse@body!65!white] (0.255,0.2) ellipse[x radius=0.23, y radius=0.09];
148 \fi% step
149 %
150 % Ears %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
151 \mouse@part@draw[\mouse@body!65!white] (0.36, 2.17) circle[radius=0.28];
152 \mouse@part@draw[\mouse@body!65!white] (-0.36, 2.17) circle[radius=0.28];
153 \unless\ifmouse@back
154 \mouse@part@draw[\mouse@body] (0.36, 2.17) circle[radius=0.15];
155 \mouse@part@draw[\mouse@body] (-0.36, 2.17) circle[radius=0.15];
156 \fi% back
157 %
158 % Tail %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
159 \unless\ifmouse@back
160 \mouse@part@draw[\mouse@body!65!white] (1.0825, 1.6326) .. controls (1.3527, 1.7527) and (1.6609, 1.3164) .. (1.5928, 1.3124) .. controls (0.9164, 2.186) and (0.8338, 0.6325) .. (0.3708, 0.4451) .. controls (0.2529, 0.3974) and (-0.0064, 0.3874) .. (-0.0064, 0.3874) .. controls (-0.0776, 0.3765) and (-0.0862, 0.5026) .. (-0.0092, 0.5034) .. controls (-0.0092, 0.5034) and (0.0363, 0.4591) .. (0.3516, 0.54360) .. controls (0.6710, 0.6988) and (0.7613, 1.4825) .. (1.0825, 1.6326) -- cycle;
161 \fi% back
162 %
163 % Body %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
164 \mouse@part@draw[\mouse@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;
165 %
166 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
167 \UseHook{tikzlings/mouse/belly}
168 \UseHook{tikzlings/belly}
169 \csname mousehookbelly\endcsname
170 \csname tikzlinghookbelly\endcsname
171 %
172 % Tail if back %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
173 \ifmouse@back
174 \mouse@part@draw[\mouse@body!65!white] (1.0825, 1.6326) .. controls (1.3527, 1.7527) and (1.6609, 1.3164) .. (1.5928, 1.3124) .. controls (0.9164, 2.186) and (0.8338, 0.6325) .. (0.3708, 0.4451) .. controls (0.2529, 0.3974) and (-0.0064, 0.3874) .. (-0.0064, 0.3874) .. controls (-0.0776, 0.3765) and (-0.0862, 0.5026) .. (-0.0092, 0.5034) .. controls (-0.0092, 0.5034) and (0.0363, 0.4591) .. (0.3516, 0.54360) .. controls (0.6710, 0.6988) and (0.7613, 1.4825) .. (1.0825, 1.6326) -- cycle;
175 \fi% back
176 %
177 % Head %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
178 \ifmouse@back
179 \mouse@part@draw[\mouse@body!65!white] (0.5, 1.8) .. controls (0.5, 1.58) and (0.2, 1.35) .. (0, 1.35) .. controls (-0.2, 1.35) and (-0.5, 1.58) .. (-0.5, 1.8) .. controls (-0.34, 2.3) and (0.34, 2.3) .. (0.5, 1.8) -- cycle;
180 \else% back
181 \mouse@part@draw[\mouse@body!65!white] (0.5, 1.8) .. controls (0.5, 1.58) and (0.2, 1.25) .. (0, 1.16) .. controls (-0.2, 1.25) and (-0.5, 1.58) .. (-0.5, 1.8) .. controls (-0.34, 2.3) and (0.34, 2.3) .. (0.5, 1.8) -- cycle;
182 \fi% back
183 %
184 % Show details only from the front %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
185 \unless\ifmouse@back
186 %
187 % Arms %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
188 \mouse@part@draw[\mouse@body!65!white,rotate around={-\mouse@rotatearms:(0.47,1.15)}] (0.47,0.93) ellipse[x radius=0.13, y radius=0.24];
189 \mouse@part@draw[\mouse@body!65!white,rotate around={\mouse@rotatearms:(-0.47,1.15)}] (-0.47,0.93) ellipse[x radius=0.13, y radius=0.24];
190 %
191 % Wiskers %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
192 \fill[\mouse@whiskers] (0.0788, 1.2046) .. controls (0.1658, 1.2199) and (0.2086, 1.1539) .. (0.2956, 1.1386) -- (0.2956, 1.1486) .. controls (0.2097, 1.1637) and (0.1648, 1.2197) .. (0.0788, 1.2046) -- cycle;
193 \fill[\mouse@whiskers] (-0.0788, 1.2046) .. controls (-0.1658, 1.2199) and (-0.2087, 1.1539) .. (-0.2956, 1.1386) -- (-0.2956, 1.1486) .. controls (-0.2097, 1.1637) and (-0.1648, 1.2197) .. (-0.0788, 1.2046) -- cycle;
194 \fill[\mouse@whiskers] (0.0752, 1.2181) .. controls (0.1583, 1.2483) and (0.2171, 1.2209) .. (0.3002, 1.1907) -- (0.3002, 1.2007) .. controls (0.2174, 1.2308) and (0.158, 1.2482) .. (0.0752, 1.2181) -- cycle;
195 \fill[\mouse@whiskers] (-0.0752, 1.2181) .. controls (-0.1583, 1.2483) and (-0.2171, 1.2209) .. (-0.3002, 1.1907) -- (-0.3002, 1.2007) .. controls (-0.2174, 1.2308) and (-0.158, 1.2482) .. (-0.0752, 1.2181) -- cycle;
196 \fill[\mouse@whiskers] (0.0671, 1.2343) .. controls (0.1414, 1.2825) and (0.2182, 1.3064) .. (0.2925, 1.2582) -- (0.2925, 1.2682) .. controls (0.2179, 1.3166) and (0.1417, 1.2827) .. (0.0671, 1.2343) -- cycle;
197 \fill[\mouse@whiskers] (-0.0671, 1.2343) .. controls (-0.1414, 1.2825) and (-0.2182, 1.3064) .. (-0.2925, 1.2582) -- (-0.2925, 1.2682) .. controls (-0.2179, 1.3166) and (-0.1417, 1.2827) .. (-0.0671, 1.2343) -- cycle;
198 %
199 % Nose %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
200 \mouse@part@draw[\mouse@body!50!black] (0, 1.248) circle[radius=0.09];
201 %
202 % Eyes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203 \mouse@part@draw[\mouse@eyes] (0.23, 1.68) circle[radius=0.05];
204 \mouse@part@draw[\mouse@eyes] (-0.23, 1.68) circle[radius=0.05];
205 %
206 \fi% back
207 %
208 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
209 \UseHook{tikzlings/mouse/body}
210 \UseHook{tikzlings/body}
211 \csname mousehookbody\endcsname
212 \csname tikzlinghookbody\endcsname
213 %
214 }
215
216 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
217 %%
218 %% Documentation
219 %%
220 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
221 %\clearpage
222 %\section[Mouse]{Tokz, the mouse}
223 %
224 %\emph{The idea for the mouse came from an Italian \LaTeX{} user -- Tokz is a combination of the Italian word for mouse and \TikZ}
225 %
226 %\subsection{Package name}
227 %
228 %\begin{tcolorbox}[title={Package usage}]
229 %\begin{samcode}
230 %\usepackage{tikzlings-mice}
231 %\end{samcode}
232 %\end{tcolorbox}
233 %
234 %\subsection{Basic Usage}
235 %
236 %\begin{tcblisting}{title={Basic mouse}}
237 %\mouse
238 %\end{tcblisting}
239 %
240 %\subsection{Options}
241 %
242 %The basic mouse can be modified by changing its colour:
243 %\begin{tcblisting}{title={Body colour}}
244 %\mouse[body=blue]
245 %\end{tcblisting}
246 %
247 %In addition to the colour of the body, the colour of various body parts can be adjusted:
248 %\begin{tcblisting}{title={Eye colour}}
249 %\mouse[eyes=red]
250 %\end{tcblisting}
251 %\begin{tcblisting}{title={Whiskers colour}}
252 %\mouse[whiskers=red]
253 %\end{tcblisting}
254 %
255 %The rotation angle of its arms can be adjusted:
256 %\begin{tcblisting}{title={Rotating the arms}}
257 %\mouse[rotatearms=40]
258 %\end{tcblisting}
259 %
260 %And the mouse can lift its legs:
261 %\begin{tcblisting}{title={Walking}}
262 %\mouse[leftstep]
263 %\mouse[rightstep,xshift=2cm]
264 %\end{tcblisting}
265 %
266 %To view the mouse from behind:
267 %\begin{tcblisting}{title={Back view}}
268 %\mouse[back]
269 %\end{tcblisting}
270 %
271 %The key \saminline|3D| will make the mouse 3-dimensional:
272 %\begin{tcblisting}{title={3D view}}
273 %\mouse[3D]
274 %\end{tcblisting}
275 %
276 %And finally the \saminline|contour| key will only draw the outlines:
277 %\begin{tcblisting}{title={Contours}}
278 %\mouse[contour=black]
279 %\end{tcblisting}