Debian Codegraph @

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

raw
1 % !TeX root = ./examples/pig.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-pigs}[2025/12/11 version v2.5 Drawing pigs in TikZ]
16
17 \RequirePackage{tikz}
18 \RequirePackage{tikzlings-addons}
19 \definecolor{piglight}{RGB}{247,205,193}
20
21 \newcommand*{\pig}[1][]{%
22 \begin{scope}%
23 \tikzset{/pig/.cd,#1}%
24 \pig@draw%
25 \end{scope}%
26 \thing[#1]%
27 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28 \UseHook{tikzlings/pig/foreground}
29 \UseHook{tikzlings/foreground}
30 \csname pighookforeground\endcsname
31 \csname tikzlinghookforeground\endcsname
32 %
33 }
34
35 \newif\ifpig@threeD
36 \newif\ifpig@back
37 \newif\ifpig@contour
38 \newif\ifpig@openmouth
39
40 \NewHook{tikzlings/pig/background}
41 \NewHook{tikzlings/pig/belly}
42 \NewHook{tikzlings/pig/body}
43 \NewHook{tikzlings/pig/foreground}
44
45 \tikzset{
46 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47 %
48 % Pass unknown keys on to tikz
49 %
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 /pig/.search also={/tikz,/pgf,/thing},
52 /pig/.cd,
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 %
55 % body
56 %
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 body/.store in = \pig@body,
59 body = piglight,
60 eyes/.store in = \pig@eyes,
61 eyes = gray,
62 eye/.forward to = /pig/eyes,
63 tail/.store in = \pig@tail,
64 tail = pig@bodysat22,
65 mouth/.store in = \pig@mouth,
66 mouth = gray,
67 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68 %
69 % options
70 %
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 openmouth/.code = \pig@openmouthtrue,
73 open mouth/.forward to = /pig/openmouth,
74 3D/.code = \pig@threeDtrue
75 \def\pig@mouth{gray!70!black},
76 back/.code = \pig@backtrue,
77 contour/.code = \pig@contourtrue
78 \def\pig@contour{#1}
79 \def\pig@mouth{#1}
80 \def\pig@tail{#1},
81 contour/.default = black,
82 outline/.forward to = /pig/contour,
83 }
84
85 \def\pig@draw{%
86 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87 %
88 % minimal bounding box size
89 %
90 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91 \path (-0.625,0.1) rectangle (0.905, 2.27);
92 %
93 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94 %
95 % store the current scale factor
96 % from https://github.com/samcarter/tikzlings/issues/3#issuecomment-461373494
97 %
98 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99 \pgfgettransformentries{\tmpscaleA}{\tmpscaleB}{\tmpscaleC}{\tmpscaleD}{\tmp}{\tmp}%
100 \pgfmathsetmacro{\scalingfactor}{sqrt(abs(\tmpscaleA*\tmpscaleD-\tmpscaleB*\tmpscaleC))*sqrt(abs((\pgf@xx/1cm)*(\pgf@yy/1cm)-(\pgf@xy/1cm)*(\pgf@yx/1cm)))}%
101 \pgfmathsetmacro{\xscalefactor}{\tmpscaleA}
102 \pgfmathsetmacro{\yscalefactor}{\tmpscaleD}
103 %
104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105 %
106 % switch between 2D, 3D and contours, from
107 % https://chat.stackexchange.com/transcript/message/45991801#45991801
108 %
109 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
110 \ifpig@threeD
111 \def\pig@part@draw[##1]{\shade[ball color=##1]}
112 \else% 3D
113 \ifpig@contour
114 \def\pig@part@draw[##1]{\draw[##1,\pig@contour,fill=white,line width=\scalingfactor*0.4pt]}
115 \else% contour
116 \def\pig@part@draw[##1]{\fill[##1]}
117 \fi% contour
118 \fi% 3D
119 %
120 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
121 %
122 % generating saturated version of body colour
123 %
124 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
125 \extractcolorspecs{\pig@body}{\pig@model}{\pig@colorspec}
126 \convertcolorspec{\pig@model}{\pig@colorspec}{hsb}{\pig@hsbcolorspec}
127 \pgfmathsetmacro{\pig@hue}{(array({\pig@hsbcolorspec},0))}
128 \pgfmathsetmacro{\pig@sat}{(array({\pig@hsbcolorspec},1)+0.22)}
129 \pgfmathsetmacro{\pig@bright}{(array({\pig@hsbcolorspec},2))}
130 \definecolor{pig@bodysat22}{hsb}{\pig@hue,\pig@sat,\pig@bright}
131 %
132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133 %
134 % Body parts
135 %
136 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
137 %
138 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139 \UseHook{tikzlings/pig/background}
140 \UseHook{tikzlings/background}
141 \csname pighookbackground\endcsname
142 \csname tikzlinghookbackground\endcsname
143 %
144 % Tail %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
145 \unless\ifpig@back
146 \draw[\pig@tail,line width=\scalingfactor*0.8pt] (0.8431, 0.583) .. controls (0.8609, 0.4063) and (0.7006, 0.361) .. (0.6384, 0.4293) .. controls (0.5762, 0.4976) and (0.5613, 0.6052) .. (0.6551, 0.629) .. controls (0.7537, 0.6541) and (0.7759, 0.5628) .. (0.7455, 0.4948) .. controls (0.6412, 0.2697) and (0.3543, 0.356) .. (0.2638, 0.4238) .. controls (0.1967, 0.4779) and (0.1788, 0.6076) .. (0.3192, 0.633) .. controls (0.6000, 0.6836) and (0.5130, 0.3048) .. (0.2098, 0.3322) .. controls (0.0809, 0.3438) and (0.0809, 0.5236) .. (0.0809, 0.5236);
147 \fi% back
148 %
149 % Feet if back %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
150 \ifpig@back
151 \pig@part@draw[pig@bodysat22] (0.3216,0.15) arc (-15:195:0.12) -- (0.16,0.15) to [bend left] (0.25,0.15) -- cycle;
152 \pig@part@draw[pig@bodysat22] (-0.3216,0.15) arc (195:-15:0.12) -- (-0.16,0.15) to[bend right] (-0.25,0.15) --cycle;
153 \fi% back
154 %
155 % Body %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
156 \pig@part@draw[\pig@body] ( 0.6, 0.8 ) .. controls ( 0.6 , 0.4) and ( 0.35, 0.16) .. ( 0.0, 0.16) .. controls (-0.35, 0.16) and (-0.6 , 0.4) .. (-0.6, 0.8 ) .. controls (-0.6 , 1.3) and (-0.35, 1.5) .. ( 0.0, 1.5) .. controls ( 0.35, 1.5) and ( 0.6 , 1.3) .. ( 0.6, 0.75) -- cycle;
157 %
158 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
159 \UseHook{tikzlings/pig/belly}
160 \UseHook{tikzlings/belly}
161 \csname pighookbelly\endcsname
162 \csname tikzlinghookbelly\endcsname
163 %
164 % Arms %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
165 \unless\ifpig@back
166 \pig@part@draw[pig@bodysat22] (-0.2402, 0.9823) .. controls (-0.2994, 1.0582) and (-0.3721, 1.0651) .. (-0.4024, 0.9978) .. controls (-0.4327, 0.9305) and (-0.4092, 0.8145) .. (-0.35, 0.7386) .. controls (-0.3311, 0.7145) and (-0.3101, 0.6964) .. (-0.289, 0.6862) .. controls (-0.2755, 0.7023) and (-0.2498, 0.7563) .. (-0.2498, 0.7563) .. controls (-0.2498, 0.7563) and (-0.1790, 0.731) .. (-0.1611, 0.746) .. controls (-0.1611, 0.746) and (-0.1809, 0.9064) .. (-0.2402, 0.9823) -- cycle;
167 \pig@part@draw[pig@bodysat22] (0.2402, 0.9823) .. controls (0.2994, 1.0582) and (0.3721, 1.0651) .. (0.4024, 0.9978) .. controls (0.4327, 0.9305) and (0.4092, 0.8145) .. (0.35, 0.7386) .. controls (0.3311, 0.7145) and (0.3101, 0.6964) .. (0.289, 0.6862) .. controls (0.2755, 0.7023) and (0.2498, 0.7563) .. (0.2498, 0.7563) .. controls (0.2498, 0.7563) and (0.1790, 0.731) .. (0.1611, 0.746) .. controls (0.1611, 0.746) and (0.1809, 0.9064) .. (0.2402, 0.9823) -- cycle;
168 \fi% back
169 %
170 % Head %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
171 \pig@part@draw[\pig@body] (0,1.64) ellipse[x radius=.5, y radius=.5];
172 %
173 % Show details only from the front %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
174 \unless\ifpig@back
175 %
176 % Eyes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
177 \pig@part@draw[\pig@eyes] (-0.09, 1.82) circle[radius=0.02];
178 \pig@part@draw[\pig@eyes] ( 0.09, 1.82) circle[radius=0.02];
179 %
180 % Nose %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181 \pig@part@draw[pig@bodysat22] (0, 1.62) ellipse[x radius=0.18, y radius=0.14];
182 \pig@part@draw[gray] (-0.06, 1.62) circle[radius=0.035];
183 \pig@part@draw[gray] ( 0.06, 1.62) circle[radius=0.035];
184 %
185 % Mouth %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
186 \ifpig@openmouth
187 \filldraw[\pig@mouth,line width=\scalingfactor*0.4pt] (0.105, 1.46) arc [start angle=-50, end angle=-130, radius=0.16];
188 \else
189 \draw[\pig@mouth,line width=\scalingfactor*0.4pt] (0.105, 1.46) arc [start angle=-50, end angle=-130, radius=0.16];
190 \fi
191 %
192 % Feet %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
193 \pig@part@draw[pig@bodysat22] (0.3216,0.15) arc (-15:195:0.12) -- (0.16,0.15) to [bend left] (0.25,0.15) -- cycle;
194 \pig@part@draw[pig@bodysat22] (-0.3216,0.15) arc (195:-15:0.12) -- (-0.16,0.15) to[bend right] (-0.25,0.15) --cycle;
195 %
196 \fi% back
197 %
198 % Ears %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
199 \pig@part@draw[pig@bodysat22] (0.22, 2.0392) .. controls (0.22, 2.1584) and (0.49460, 2.255) .. (0.49460, 2.255) .. controls (0.49460, 2.255) and (0.5300, 1.86) .. (0.3721, 1.86) .. controls (0.2891, 1.86) and (0.22, 1.9201) .. (0.22, 2.0392) -- cycle;
200 \pig@part@draw[\pig@body] (0.22, 2.0392) .. controls (0.26, 2.1584) and (0.47, 2.22) .. (0.47, 2.20) .. controls (0.47, 2.2) and (0.49, 1.9) .. (0.3721, 1.9) .. controls (0.2891, 1.88) and (0.22, 1.88) .. (0.22, 2.0392) -- cycle;
201 \pig@part@draw[pig@bodysat22] (-0.22, 2.0392) .. controls (-0.22, 2.1584) and (-0.49460, 2.255) .. (-0.49460, 2.255) .. controls (-0.49460, 2.255) and (-0.5300, 1.86) .. (-0.3721, 1.86) .. controls (-0.2891, 1.86) and (-0.22, 1.9201) .. (-0.22, 2.0392) -- cycle;
202 \pig@part@draw[\pig@body] (-0.22, 2.0392) .. controls (-0.26, 2.1584) and (-0.47, 2.22) .. (-0.47, 2.20) .. controls (-0.47, 2.2) and (-0.49, 1.9) .. (-0.3721, 1.9) .. controls (-0.2891, 1.88) and (-0.22, 1.88) .. (-0.22, 2.0392) -- cycle;
203 %
204 % Tail if back %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
205 \ifpig@back
206 \draw[\pig@tail,line width=\scalingfactor*0.8pt] (0.8431, 0.583) .. controls (0.8609, 0.4063) and (0.7006, 0.361) .. (0.6384, 0.4293) .. controls (0.5762, 0.4976) and (0.5613, 0.6052) .. (0.6551, 0.629) .. controls (0.7537, 0.6541) and (0.7759, 0.5628) .. (0.7455, 0.4948) .. controls (0.6412, 0.2697) and (0.3543, 0.356) .. (0.2638, 0.4238) .. controls (0.1967, 0.4779) and (0.1788, 0.6076) .. (0.3192, 0.633) .. controls (0.6000, 0.6836) and (0.5130, 0.3048) .. (0.2098, 0.3322) .. controls (0.0809, 0.3438) and (0.0809, 0.5236) .. (0.0809, 0.5236);
207 \fi% back
208 %
209 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
210 \UseHook{tikzlings/pig/body}
211 \UseHook{tikzlings/body}
212 \csname pighookbody\endcsname
213 \csname tikzlinghookbody\endcsname
214 %
215 }
216
217 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
218 %%
219 %% Documentation
220 %%
221 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
222 %\clearpage
223 %\section[Pig]{Ms Piggy, the pig}
224 %
225 %\emph{Added on February 5th, 2019 to commemorate the Chinese year of the pig}
226 %
227 %\subsection{Package name}
228 %
229 %\begin{tcolorbox}[title={Package usage}]
230 %\begin{samcode}
231 %\usepackage{tikzlings-pigs}
232 %\end{samcode}
233 %\end{tcolorbox}
234 %
235 %\subsection{Basic Usage}
236 %
237 %\begin{tcblisting}{title={Basic pig}}
238 %\pig
239 %\end{tcblisting}
240 %
241 %\subsection{Options}
242 %
243 %The basic pig can be modified by changing its colour:
244 %\begin{tcblisting}{title={Body colour}}
245 %\pig[body=blue]
246 %\end{tcblisting}
247 %
248 %In addition to the colour of the body, the colour of various body parts can be adjusted:
249 %\begin{tcblisting}{title={Eye colour}}
250 %\pig[eyes=red]
251 %\end{tcblisting}
252 %\begin{tcblisting}{title={Tail colour}}
253 %\pig[tail=red]
254 %\end{tcblisting}
255 %\begin{tcblisting}{title={Mouth colour}}
256 %\pig[mouth=red]
257 %\end{tcblisting}
258 %
259 % The pig can open its mouth:
260 %\begin{tcblisting}{title={Open mouth}}
261 %\pig[openmouth]
262 %\end{tcblisting}
263 %
264 %To view the pig from behind:
265 %\begin{tcblisting}{title={Back view}}
266 %\pig[back]
267 %\end{tcblisting}
268 %
269 %The key \saminline|3D| will make the pig 3-dimensional:
270 %\begin{tcblisting}{title={3D view}}
271 %\pig[3D]
272 %\end{tcblisting}
273 %
274 %And finally the \saminline|contour| key will only draw the outlines:
275 %\begin{tcblisting}{title={Contours}}
276 %\pig[contour=black]
277 %\end{tcblisting}