Debian Codegraph @

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

raw
1 % !TeX root = ./examples/penguin.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-penguins}[2025/12/11 version v2.5 Draw penguins in TikZ]
16
17 \RequirePackage{tikz}
18 \RequirePackage{tikzlings-addons}
19
20 \newcommand*{\penguin}[1][]{%
21 \begin{scope}%
22 \tikzset{/penguin/.cd,#1}%
23 \penguin@draw%
24 \end{scope}%
25 \thing[#1]%
26 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27 \UseHook{tikzlings/penguin/foreground}
28 \UseHook{tikzlings/foreground}
29 \csname penguinhookforeground\endcsname
30 \csname tikzlinghookforeground\endcsname
31 %
32 }
33
34 \newif\ifpenguin@threeD
35 \newif\ifpenguin@back
36 \newif\ifpenguin@contour
37
38 \NewHook{tikzlings/penguin/background}
39 \NewHook{tikzlings/penguin/belly}
40 \NewHook{tikzlings/penguin/body}
41 \NewHook{tikzlings/penguin/foreground}
42
43 \tikzset{
44 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 %
46 % Pass unknown keys on to tikz
47 %
48 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 /penguin/.search also={/tikz,/pgf,/thing},
50 /penguin/.cd,
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 %
53 % body
54 %
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 body/.store in = \penguin@body,
57 body = black,
58 belly/.store in = \penguin@belly,
59 belly = white!95!black,
60 feet/.store in = \penguin@feet,
61 feet = yellow!50!orange,
62 foot/.forward to = /penguin/feet,
63 bill/.store in = \penguin@bill,
64 bill = orange,
65 eyes/.store in = \penguin@eyes,
66 eyes = white!95!black,
67 eye/.forward to = /penguin/eyes,
68 pupils/.store in = \penguin@pupils,
69 pupils = black,
70 pupil/.forward to = /penguin/pupils,
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 %
73 % options
74 %
75 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76 3D/.code = \penguin@threeDtrue,
77 back/.code = \penguin@backtrue,
78 contour/.code = \penguin@contourtrue
79 \def\penguin@contour{#1},
80 contour/.default = black,
81 outline/.forward to = /penguin/contour,
82 }
83
84 \def\penguin@draw{%
85 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86 %
87 % minimal bounding box size
88 %
89 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90 \path (-0.865, 0.15) rectangle (0.865, 2.13);
91 %
92 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
93 %
94 % store the current scale factor
95 % from https://github.com/samcarter/tikzlings/issues/3#issuecomment-461373494
96 %
97 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
98 \pgfgettransformentries{\tmpscaleA}{\tmpscaleB}{\tmpscaleC}{\tmpscaleD}{\tmp}{\tmp}%
99 \pgfmathsetmacro{\scalingfactor}{sqrt(abs(\tmpscaleA*\tmpscaleD-\tmpscaleB*\tmpscaleC))*sqrt(abs((\pgf@xx/1cm)*(\pgf@yy/1cm)-(\pgf@xy/1cm)*(\pgf@yx/1cm)))}%
100 \pgfmathsetmacro{\xscalefactor}{\tmpscaleA}
101 \pgfmathsetmacro{\yscalefactor}{\tmpscaleD}
102 %
103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104 %
105 % switch between 2D, 3D and contours, from
106 % https://chat.stackexchange.com/transcript/message/45991801#45991801
107 %
108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109 \ifpenguin@threeD
110 \def\penguin@part@draw[##1]{\shade[ball color=##1]}
111 \else% 3D
112 \ifpenguin@contour
113 \def\penguin@part@draw[##1]{\draw[##1,\penguin@contour,fill=white,line width=\scalingfactor*0.4pt]}
114 \else% contour
115 \def\penguin@part@draw[##1]{\fill[##1]}
116 \fi% contour
117 \fi% 3D
118 %
119 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120 %
121 % Body parts
122 %
123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124 %
125 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
126 \UseHook{tikzlings/penguin/background}
127 \UseHook{tikzlings/background}
128 \csname penguinhookbackground\endcsname
129 \csname tikzlinghookbackground\endcsname
130 %
131 % Arms %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
132 \penguin@part@draw[\penguin@body] (0.575,1.2) ellipse[x radius=0.38, y radius=0.1, rotate=-50];
133 \penguin@part@draw[\penguin@body] (-0.575,1.2) ellipse[x radius=0.38, y radius=0.1, rotate=50];
134 %
135 % Feet if back %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136 \ifpenguin@back
137 \penguin@part@draw[\penguin@feet] (-0.265, 0.3941) .. controls (-0.283, 0.4505) and (-0.373, 0.6014) .. (-0.470, 0.6533) .. controls (-0.571, 0.7075) and (-0.576, 0.6369) .. (-0.554, 0.596) .. controls (-0.526, 0.5416) and (-0.573, 0.5302) .. (-0.602, 0.5384) .. controls (-0.695, 0.5653) and (-0.767, 0.5169) .. (-0.684, 0.434) .. controls (-0.664, 0.4137) and (-0.587, 0.3557) .. (-0.699, 0.3492) .. controls (-0.772, 0.345) and (-0.779, 0.268) .. (-0.689, 0.2445) .. controls (-0.597, 0.2206) and (-0.476, 0.2043) .. (-0.34, 0.2096) .. controls (-0.252, 0.2131) and (-0.237, 0.3059) .. (-0.265, 0.3941) -- cycle;
138 \penguin@part@draw[\penguin@feet] (0.265, 0.3941) .. controls (0.283, 0.4505) and (0.3725, 0.6014) .. (0.469, 0.6533) .. controls (0.571, 0.7075) and (0.5756, 0.6369) .. (0.554, 0.596) .. controls (0.526, 0.5416) and (0.5733, 0.5302) .. (0.602, 0.5384) .. controls (0.695, 0.5653) and (0.7672, 0.5169) .. (0.684, 0.434) .. controls (0.663, 0.4137) and (0.587, 0.3557) .. (0.699, 0.3492) .. controls (0.772, 0.345) and (0.7789, 0.268) .. (0.689, 0.2445) .. controls (0.597, 0.2206) and (0.4764, 0.2043) .. (0.34, 0.2096) .. controls (0.252, 0.2131) and (0.2368, 0.3059) .. (0.265, 0.3941) -- cycle;
139 \fi% back
140 %
141 % Body %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
142 \penguin@part@draw[\penguin@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;
143 %
144 % Belly %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
145 \unless\ifpenguin@back
146 \penguin@part@draw[\penguin@belly] (0, 0.6) ellipse[x radius=0.48, y radius=0.35];
147 \fi% back
148 %
149 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
150 \UseHook{tikzlings/penguin/belly}
151 \UseHook{tikzlings/belly}
152 \csname penguinhookbelly\endcsname
153 \csname tikzlinghookbelly\endcsname
154 %
155 % Feet %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
156 \unless\ifpenguin@back
157 \penguin@part@draw[\penguin@feet] (-0.265, 0.3941) .. controls (-0.283, 0.4505) and (-0.373, 0.6014) .. (-0.470, 0.6533) .. controls (-0.571, 0.7075) and (-0.576, 0.6369) .. (-0.554, 0.596) .. controls (-0.526, 0.5416) and (-0.573, 0.5302) .. (-0.602, 0.5384) .. controls (-0.695, 0.5653) and (-0.767, 0.5169) .. (-0.684, 0.434) .. controls (-0.664, 0.4137) and (-0.587, 0.3557) .. (-0.699, 0.3492) .. controls (-0.772, 0.345) and (-0.779, 0.268) .. (-0.689, 0.2445) .. controls (-0.597, 0.2206) and (-0.476, 0.2043) .. (-0.34, 0.2096) .. controls (-0.252, 0.2131) and (-0.237, 0.3059) .. (-0.265, 0.3941) -- cycle;
158 \penguin@part@draw[\penguin@feet] (0.265, 0.3941) .. controls (0.283, 0.4505) and (0.3725, 0.6014) .. (0.469, 0.6533) .. controls (0.571, 0.7075) and (0.5756, 0.6369) .. (0.554, 0.596) .. controls (0.526, 0.5416) and (0.5733, 0.5302) .. (0.602, 0.5384) .. controls (0.695, 0.5653) and (0.7672, 0.5169) .. (0.684, 0.434) .. controls (0.663, 0.4137) and (0.587, 0.3557) .. (0.699, 0.3492) .. controls (0.772, 0.345) and (0.7789, 0.268) .. (0.689, 0.2445) .. controls (0.597, 0.2206) and (0.4764, 0.2043) .. (0.34, 0.2096) .. controls (0.252, 0.2131) and (0.2368, 0.3059) .. (0.265, 0.3941) -- cycle;
159 \fi% back
160 %
161 % Eyes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
162 \unless\ifpenguin@back
163 \ifpenguin@contour
164 \penguin@part@draw[\penguin@eyes] (-0.175,1.64) ellipse[x radius=0.1, y radius=0.15, rotate=-10];
165 \penguin@part@draw[\penguin@pupils] (-0.145,1.625) ellipse[x radius=0.0357, y radius=0.0714, rotate=-3];
166 \penguin@part@draw[\penguin@eyes] (0.175,1.64) ellipse[x radius=0.1, y radius=0.15, rotate=10];
167 \penguin@part@draw[\penguin@pupils] (0.145,1.625) ellipse[x radius=0.0357, y radius=0.0714, rotate=3];
168 \else% contour
169 \fill[\penguin@eyes] (-0.175,1.64) ellipse[x radius=0.1, y radius=0.15, rotate=-10];
170 \fill[\penguin@pupils] (-0.145,1.625) ellipse[x radius=0.0357, y radius=0.0714, rotate=-3];
171 \fill[\penguin@eyes] (0.175,1.64) ellipse[x radius=0.1, y radius=0.15, rotate=10];
172 \fill[\penguin@pupils] (0.145,1.625) ellipse[x radius=0.0357, y radius=0.0714, rotate=3];
173 \fi% contour
174 \fi% back
175 %
176 % Bill %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
177 \unless\ifpenguin@back
178 \penguin@part@draw[\penguin@bill] (0.323, 1.4591) .. controls (0.1467, 1.3257) and (0.1066, 1.4365) .. (0, 1.4358) .. controls (-0.1066, 1.4365) and (-0.1467, 1.3257) .. (-0.323, 1.4591) .. controls (-0.1267, 1.075) and (0.1267, 1.075) .. (0.323, 1.4591) -- cycle;
179 \fi% back
180 %
181 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
182 \UseHook{tikzlings/penguin/body}
183 \UseHook{tikzlings/body}
184 \csname penguinhookbody\endcsname
185 \csname tikzlinghookbody\endcsname
186 %
187 }
188
189 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
190 %%
191 %% Documentation
192 %%
193 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
194 %\clearpage
195 %\section[Penguin]{Tux, the penguin}
196 %
197 %\emph{Dedicated to the Linux mascot}
198 %
199 %\subsection{Package name}
200 %
201 %\begin{tcolorbox}[title={Package usage}]
202 %\begin{samcode}
203 %\usepackage{tikzlings-penguins}
204 %\end{samcode}
205 %\end{tcolorbox}
206 %
207 %\subsection{Basic Usage}
208 %
209 %\begin{tcblisting}{title={Basic penguin}}
210 %\penguin
211 %\end{tcblisting}
212 %
213 %\subsection{Options}
214 %
215 %The basic penguin can be modified by changing its colour:
216 %\begin{tcblisting}{title={Body colour}}
217 %\penguin[body=blue]
218 %\end{tcblisting}
219 %
220 %In addition to the colour of the body, the colour of various body parts can be adjusted:
221 %\begin{tcblisting}{title={Eye colour}}
222 %\penguin[eyes=red]
223 %\end{tcblisting}
224 %\begin{tcblisting}{title={Pupil colour}}
225 %\penguin[pupils=red]
226 %\end{tcblisting}
227 %\begin{tcblisting}{title={Bill colour}}
228 %\penguin[bill=red]
229 %\end{tcblisting}
230 %\begin{tcblisting}{title={Belly colour}}
231 %\penguin[belly=red]
232 %\end{tcblisting}
233 %\begin{tcblisting}{title={Foot colour}}
234 %\penguin[feet=red]
235 %\end{tcblisting}
236 %
237 %To view the penguin from behind:
238 %\begin{tcblisting}{title={Back view}}
239 %\penguin[back]
240 %\end{tcblisting}
241 %
242 %The key \saminline|3D| will make the penguin 3-dimensional:
243 %\begin{tcblisting}{title={3D view}}
244 %\penguin[3D]
245 %\end{tcblisting}
246 %
247 %And finally the \saminline|contour| key will only draw the outlines:
248 %\begin{tcblisting}{title={Contours}}
249 %\penguin[contour=black]
250 %\end{tcblisting}