Debian Codegraph @

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

raw
1 % !TeX root = ./examples/panda.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-pandas}[2025/12/11 version v2.5 Drawing pandas in TikZ]
16
17 \RequirePackage{tikz}
18 \RequirePackage{tikzlings-addons}
19
20 \newcommand*{\panda}[1][]{%
21 \begin{scope}%
22 \tikzset{/panda/.cd,#1}%
23 \panda@draw%
24 \end{scope}%
25 \thing[#1]%
26 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27 \UseHook{tikzlings/panda/foreground}
28 \UseHook{tikzlings/foreground}
29 \csname pandahookforeground\endcsname
30 \csname tikzlinghookforeground\endcsname
31 %
32 }
33
34 \newif\ifpanda@threeD
35 \newif\ifpanda@back
36 \newif\ifpanda@contour
37 \newif\ifpanda@openmouth
38
39 \NewHook{tikzlings/panda/background}
40 \NewHook{tikzlings/panda/belly}
41 \NewHook{tikzlings/panda/body}
42 \NewHook{tikzlings/panda/foreground}
43
44 \tikzset{
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46 %
47 % Pass unknown keys on to tikz
48 %
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 /panda/.search also={/tikz,/pgf,/thing},
51 /panda/.cd,
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 %
54 % body
55 %
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 body/.store in = \panda@body,
58 body = white!90!gray,
59 eyes/.store in = \panda@eyes,
60 eyes = white,
61 eye/.forward to = /panda/eyes,
62 pupils/.store in = \panda@pupils,
63 pupils = black,
64 pupil/.forward to = /panda/pupils,
65 mouth/.store in = \panda@mouth,
66 mouth = black,
67 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68 %
69 % options
70 %
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 openmouth/.code = \panda@openmouthtrue,
73 open mouth/.forward to = /panda/openmouth,
74 3D/.code = \panda@threeDtrue,
75 back/.code = \panda@backtrue,
76 contour/.code = \panda@contourtrue
77 \def\panda@contour{#1}
78 \def\panda@mouth{#1},
79 contour/.default = black,
80 outline/.forward to = /panda/contour,
81 }
82
83 \def\panda@draw{%
84 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85 %
86 % minimal bounding box size
87 %
88 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89 \path (-0.62,0.05) rectangle (0.62, 2.18);
90 %
91 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92 %
93 % store the current scale factor
94 % from https://github.com/samcarter/tikzlings/issues/3#issuecomment-461373494
95 %
96 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97 \pgfgettransformentries{\tmpscaleA}{\tmpscaleB}{\tmpscaleC}{\tmpscaleD}{\tmp}{\tmp}%
98 \pgfmathsetmacro{\scalingfactor}{sqrt(abs(\tmpscaleA*\tmpscaleD-\tmpscaleB*\tmpscaleC))*sqrt(abs((\pgf@xx/1cm)*(\pgf@yy/1cm)-(\pgf@xy/1cm)*(\pgf@yx/1cm)))}%
99 \pgfmathsetmacro{\xscalefactor}{\tmpscaleA}
100 \pgfmathsetmacro{\yscalefactor}{\tmpscaleD}
101 %
102 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
103 %
104 % switch between 2D, 3D and contours, from
105 % https://chat.stackexchange.com/transcript/message/45991801#45991801
106 %
107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108 \ifpanda@threeD
109 \def\panda@part@draw[##1]{\shade[ball color=##1]}
110 \else% 3D
111 \ifpanda@contour
112 \def\panda@part@draw[##1]{\draw[##1,\panda@contour,fill=white,line width=\scalingfactor*0.4pt]}
113 \else% contour
114 \def\panda@part@draw[##1]{\fill[##1]}
115 \fi% contour
116 \fi% 3D
117 %
118 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
119 %
120 % Body parts
121 %
122 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
123 %
124 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
125 \UseHook{tikzlings/panda/background}
126 \UseHook{tikzlings/background}
127 \csname pandahookbackground\endcsname
128 \csname tikzlinghookbackground\endcsname
129 %
130 % Feet if back %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 \ifpanda@back
132 \panda@part@draw[black] (0.32, 0.27) circle[radius=0.2];
133 \panda@part@draw[black] (-0.32, 0.27) circle[radius=0.2];
134 \fi% back
135 %
136 % Body %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
137 \panda@part@draw[\panda@body] (0,0.78) ellipse[x radius=0.57, y radius=0.65];
138 %
139 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
140 \UseHook{tikzlings/panda/belly}
141 \UseHook{tikzlings/belly}
142 \csname pandahookbelly\endcsname
143 \csname tikzlinghookbelly\endcsname
144 %
145 % Arms %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146 \unless\ifpanda@back
147 \begin{scope}[yshift=-0.08cm]
148 \panda@part@draw[black] (0.28,0.93) ellipse[x radius=0.24, y radius=0.13, rotate=70];
149 \panda@part@draw[black] (-0.28,0.93) ellipse[x radius=0.24, y radius=0.13, rotate=-70];
150 \end{scope}
151 \fi% back
152 %
153 % Feet %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
154 \unless\ifpanda@back
155 \panda@part@draw[black] (0.32, 0.27) circle[radius=0.2];
156 \panda@part@draw[black] (-0.32, 0.27) circle[radius=0.2];
157 \fi% back
158 %
159 % Ears %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
160 \panda@part@draw[black] (0.32, 2) circle[radius=0.15];
161 \panda@part@draw[black] (-0.32, 2) circle[radius=0.15];
162 %
163 % Head %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
164 \panda@part@draw[\panda@body] (0.4897, 1.5886) .. controls (0.4614, 1.8238) and (0.25, 2.1172) .. (0, 2.1134) .. controls (-0.25, 2.1172) and (-0.4614, 1.8238) .. (-0.4897, 1.5886) .. controls (-0.5261, 1.3269) and (-0.2748, 1.2377) .. (0, 1.2377) .. controls (0.2748, 1.2377) and (0.5261, 1.3269) .. (0.4897, 1.5886) -- cycle;
165 %
166 % Show details only from the front %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
167 \unless\ifpanda@back
168 %
169 % Eyes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
170 \panda@part@draw[black] (0.3732, 1.6905) .. controls (0.3498, 1.767) and (0.2032, 1.8059) .. (0.0944, 1.7715) .. controls (-0.0145, 1.7371) and (0.173, 1.5479) .. (0.2508, 1.5443) .. controls (0.3286, 1.5407) and (0.3965, 1.614) .. (0.3732, 1.6905) -- cycle;
171 \panda@part@draw[black] (-0.3732, 1.6905) .. controls (-0.3498, 1.767) and (-0.2032, 1.8059) .. (-0.0944, 1.7715) .. controls (0.0145, 1.7371) and (-0.173, 1.5479) .. (-0.2508, 1.5443) .. controls (-0.3286, 1.5407) and (-0.3965, 1.614) .. (-0.3732, 1.6905) -- cycle;
172 \panda@part@draw[\panda@eyes] (-0.18, 1.7) circle[radius=0.05];
173 \panda@part@draw[\panda@eyes] (0.18, 1.7) circle[radius=0.05];
174 \panda@part@draw[\panda@pupils] (0.17, 1.695) circle[radius=0.02];
175 \panda@part@draw[\panda@pupils] (-0.17, 1.695) circle[radius=0.02];
176 %
177 % Mouth %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
178 \ifpanda@openmouth
179 \filldraw[\panda@mouth,line width=\scalingfactor*0.2pt] (-0.16, 1.477) .. controls (-0.16, 1.477) and (-0.062, 1.37) .. (0, 1.506) .. controls (0.062, 1.37) and (0.16, 1.477) .. (0.16, 1.477) (0.16,1.477) arc [start angle=-20, end angle=-160, radius=0.17];
180 \else
181 \draw[\panda@mouth,line width=\scalingfactor*0.2pt] (-0.16, 1.477) .. controls (-0.16, 1.477) and (-0.062, 1.37) .. (0, 1.506) .. controls (0.062, 1.37) and (0.16, 1.477) .. (0.16, 1.477);
182 \fi
183 %
184 % Nose %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
185 \panda@part@draw[black] (0,1.55) ellipse[x radius=0.07, y radius=0.04];
186 %
187 \fi% back
188 %
189 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
190 \UseHook{tikzlings/panda/body}
191 \UseHook{tikzlings/body}
192 \csname pandahookbody\endcsname
193 \csname tikzlinghookbody\endcsname
194 %
195 }
196
197 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
198 %%
199 %% Documentation
200 %%
201 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
202 %\clearpage
203 %\section[Panda]{Meng Meng, the panda}
204 %
205 %\emph{Meng Meng is named after one of the pandas at the zoological garden Berlin}
206 %
207 %\subsection{Package name}
208 %
209 %\begin{tcolorbox}[title={Package usage}]
210 %\begin{samcode}
211 %\usepackage{tikzlings-pandas}
212 %\end{samcode}
213 %\end{tcolorbox}
214 %
215 %\subsection{Basic Usage}
216 %
217 %\begin{tcblisting}{title={Basic panda}}
218 %\panda
219 %\end{tcblisting}
220 %
221 %\subsection{Options}
222 %
223 %The basic panda can be modified by changing its colour:
224 %\begin{tcblisting}{title={Body colour}}
225 %\panda[body=blue]
226 %\end{tcblisting}
227 %
228 %In addition to the colour of the body, the colour of various body parts can be adjusted:
229 %\begin{tcblisting}{title={Eye colour}}
230 %\panda[eyes=red]
231 %\end{tcblisting}
232 %\begin{tcblisting}{title={Pupil colour}}
233 %\panda[pupils=red]
234 %\end{tcblisting}
235 %\begin{tcblisting}{title={Mouth colour}}
236 %\panda[mouth=red]
237 %\end{tcblisting}
238 %
239 % The panda can open its mouth:
240 %\begin{tcblisting}{title={Open mouth}}
241 %\panda[openmouth]
242 %\end{tcblisting}
243 %
244 %To view the panda from behind:
245 %\begin{tcblisting}{title={Back view}}
246 %\panda[back]
247 %\end{tcblisting}
248 %
249 %The key \saminline|3D| will make the panda 3-dimensional:
250 %\begin{tcblisting}{title={3D view}}
251 %\panda[3D]
252 %\end{tcblisting}
253 %
254 %And finally the \saminline|contour| key will only draw the outlines:
255 %\begin{tcblisting}{title={Contours}}
256 %\panda[contour=black]
257 %\end{tcblisting}