Debian Codegraph @

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

raw
1 % !TeX root = ./examples/sheep.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-sheep}[2025/12/11 version v2.5 Drawing sheep in TikZ]
16
17 \RequirePackage{tikz}
18 \RequirePackage{tikzlings-addons}
19 \usetikzlibrary{decorations.pathmorphing}
20 \usetikzlibrary{fadings}
21
22 \tikzfading[name=sheep@blush,inner color=transparent!50,outer color=transparent!100]
23
24 \newcommand*{\sheep}[1][]{%
25 \begin{scope}%
26 \tikzset{/sheep/.cd,#1}%
27 \sheep@draw%
28 \end{scope}%
29 \thing[#1]%
30 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 \UseHook{tikzlings/sheep/foreground}
32 \UseHook{tikzlings/foreground}
33 \csname sheephookforeground\endcsname
34 \csname tikzlinghookforeground\endcsname
35 }
36
37 \newif\ifsheep@threeD
38 \newif\ifsheep@monocle
39 \newif\ifsheep@blush
40 \newif\ifsheep@back
41 \newif\ifsheep@contour
42
43 \NewHook{tikzlings/sheep/background}
44 \NewHook{tikzlings/sheep/belly}
45 \NewHook{tikzlings/sheep/body}
46 \NewHook{tikzlings/sheep/foreground}
47
48 \tikzset{
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 %
51 % Pass unknown keys on to tikz
52 %
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 /sheep/.search also={/tikz,/pgf,/thing},
55 /sheep/.cd,
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 %
58 % body
59 %
60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61 body/.store in = \sheep@body,
62 body = brown!50!darkgray!97!yellow!50!darkgray,
63 eyes/.store in = \sheep@eyes,
64 eyes = sheep@bright!50!black,
65 eye/.forward to = /sheep/eyes,
66 nose/.store in = \sheep@nose,
67 nose = sheep@bright!50!black,
68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69 %
70 % options
71 %
72 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 blush/.code = \sheep@blushtrue
74 \def\sheep@blushcolor{#1},
75 blush/.default = red,
76 monocle/.code = \sheep@monocletrue,
77 3D/.code = \sheep@threeDtrue,
78 back/.code = \sheep@backtrue,
79 contour/.code = \sheep@contourtrue
80 \def\sheep@contour{#1}
81 \def\sheep@blushcolor{#1}
82 \def\sheep@nose{#1},
83 contour/.default = black,
84 outline/.forward to = /sheep/contour,
85 }
86
87 \def\sheep@draw{%
88 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89 %
90 % minimal bounding box size
91 %
92 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
93 \path (-0.7,0.08) rectangle (0.7,2.33);
94 %
95 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 %
97 % store the current scale factor
98 % from https://github.com/samcarter/tikzlings/issues/3#issuecomment-461373494
99 %
100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101 \pgfgettransformentries{\tmpscaleA}{\tmpscaleB}{\tmpscaleC}{\tmpscaleD}{\tmp}{\tmp}%
102 \pgfmathsetmacro{\scalingfactor}{sqrt(abs(\tmpscaleA*\tmpscaleD-\tmpscaleB*\tmpscaleC))*sqrt(abs((\pgf@xx/1cm)*(\pgf@yy/1cm)-(\pgf@xy/1cm)*(\pgf@yx/1cm)))}%
103 \pgfmathsetmacro{\xscalefactor}{\tmpscaleA}
104 \pgfmathsetmacro{\yscalefactor}{\tmpscaleD}
105 \pgfmathsetmacro{\decoscalefactor}{sign(\tmpscaleA)*sign(\tmpscaleD)*\scalingfactor}%
106 %
107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108 %
109 % switch between 2D, 3D and contours, from
110 % https://chat.stackexchange.com/transcript/message/45991801#45991801
111 %
112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113 \ifsheep@threeD
114 \def\sheep@part@draw[##1]{\shade[ball color=##1]}
115 \else% 3D
116 \ifsheep@contour
117 \def\sheep@part@draw[##1]{\draw[##1,\sheep@contour,fill=white,line width=\scalingfactor*0.4pt]}
118 \else% contour
119 \def\sheep@part@draw[##1]{\fill[##1]}
120 \fi% contour
121 \fi% 3D
122 %
123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124 %
125 % generating saturated/brighter version of body colour
126 %
127 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128 \extractcolorspecs{\sheep@body}{\sheep@model}{\sheep@colorspec}
129 \convertcolorspec{\sheep@model}{\sheep@colorspec}{hsb}{\sheep@hsbcolorspec}
130 \pgfmathsetmacro{\sheep@hue}{(array({\sheep@hsbcolorspec},0))}
131 \pgfmathsetmacro{\sheep@sat}{(array({\sheep@hsbcolorspec},1))}
132 \pgfmathsetmacro{\sheep@bright}{(array({\sheep@hsbcolorspec},2))+0.1}
133 \definecolor{sheep@bright}{hsb}{\sheep@hue,\sheep@sat,\sheep@bright}
134 %
135 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136 %
137 % Body parts
138 %
139 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
140 %
141 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
142 \UseHook{tikzlings/sheep/background}
143 \UseHook{tikzlings/background}
144 \csname sheephookbackground\endcsname
145 \csname tikzlinghookbackground\endcsname
146 %
147 % Ears %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148 \sheep@part@draw[sheep@bright] (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;
149 \sheep@part@draw[sheep@bright!55!white] (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;
150 \sheep@part@draw[sheep@bright] (-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;
151 \sheep@part@draw[sheep@bright!55!white] (-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;
152 %
153 % Feet if back %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
154 \ifsheep@back
155 \sheep@part@draw[sheep@bright] (0.3216,0.15) arc (-15:195:0.12) -- (0.16,0.15) to [bend left] (0.25,0.15) -- cycle;
156 \sheep@part@draw[sheep@bright] (-0.3216,0.15) arc (195:-15:0.12) -- (-0.16,0.15) to[bend right] (-0.25,0.15) --cycle;
157 \fi% back
158 %
159 % Body %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
160 \sheep@part@draw[\sheep@body,decorate,decoration={bumps,amplitude=\decoscalefactor*2.5pt,segment length=\scalingfactor*10pt}] (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;
161 %
162 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
163 \UseHook{tikzlings/sheep/belly}
164 \UseHook{tikzlings/belly}
165 \csname sheephookbelly\endcsname
166 \csname tikzlinghookbelly\endcsname
167 %
168 % Arms %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
169 \unless\ifsheep@back
170 \sheep@part@draw[sheep@bright!45!white!95!orange] (-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;
171 \sheep@part@draw[sheep@bright!45!white!95!orange] (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;
172 \fi% back
173 %
174 % Hair %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
175 \sheep@part@draw[\sheep@body,decorate,decoration={bumps,amplitude=\decoscalefactor*2.5pt,segment length=\scalingfactor*10pt}] (-0.275,1.98) -- (-0.2,2.2) -- (-0.008,2.2) -- (0.2,2.2) -- (0.275,1.98) -- cycle;
176 %
177 % Tail if back %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
178 \ifsheep@back
179 \sheep@part@draw[sheep@bright!45!white!95!orange,rounded corners=\scalingfactor*0.1pt] (0,0.7) -- (0.08, 0.3236) arc (0:-180:\scalingfactor*2pt) -- cycle;
180 \fi% back
181 %
182 % Show details only from the front %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
183 \unless\ifsheep@back
184 %
185 % Head %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
186 \sheep@part@draw[sheep@bright!45!white!95!orange] (0.4, 1.8) .. controls (0.4, 1.5) and (0.2, 1.25) .. (0, 1.16) .. controls (-0.2, 1.25) and (-0.4, 1.5) .. (-0.4, 1.8) .. controls (-0.34, 2.3) and (0.34, 2.3) .. (0.4, 1.8) -- cycle;
187 %
188 % Ears %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
189 \sheep@part@draw[sheep@bright] (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;
190 \sheep@part@draw[sheep@bright!55!white] (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;
191 \sheep@part@draw[sheep@bright] (-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;
192 \sheep@part@draw[sheep@bright!55!white] (-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;
193 %
194 % Eyes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
195 \unless\ifsheep@back
196 \sheep@part@draw[\sheep@eyes] (0.2, 1.66) circle[radius=0.06];
197 \sheep@part@draw[\sheep@eyes] (-0.2, 1.66) circle[radius=0.06];
198 \fi% back
199 %
200 % Nose %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
201 \draw[\sheep@nose,line width=\scalingfactor*0.8pt,line cap=round] (0.16,1.43) arc [start angle=-30, end angle=-150, radius=0.185] (0.0,1.335) -- (0,1.175);
202 %
203 % Feet %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
204 \sheep@part@draw[sheep@bright!45!white!95!orange] (0.3216,0.13) arc (-15:195:0.10) -- (0.16,0.13) to [bend left] (0.25,0.13) -- cycle;
205 \sheep@part@draw[sheep@bright!45!white!95!orange] (-0.3216,0.13) arc (195:-15:0.10) -- (-0.16,0.13) to[bend right] (-0.25,0.13) --cycle;
206 %
207 % Hair %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
208 \sheep@part@draw[\sheep@body,decorate,decoration={bumps,amplitude=\decoscalefactor*2.5pt,segment length=\scalingfactor*10pt}] (-0.275,1.98) -- (-0.2,2.2) -- (-0.008,2.2) -- (0.2,2.2) -- (0.275,1.98) -- cycle;
209 %
210 % Blush %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
211 \ifsheep@blush
212 \fill[\sheep@blushcolor,path fading=sheep@blush] (-0.25, 1.5) circle[radius=0.1];
213 \fill[\sheep@blushcolor,path fading=sheep@blush] (0.25, 1.5) circle[radius=0.1];
214 \fi% blush
215 %
216 % monocle %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
217 \ifsheep@monocle
218 \draw[black,line width=\scalingfactor*0.4pt] (0.2, 1.66) circle[radius=0.09];
219 \draw[black,line width=\scalingfactor*0.4pt,rounded corners=\scalingfactor*0.01pt] (0.26,1.6) .. controls (0.3,1.54) .. (0.3,1.5) .. controls (0.28,1.45) .. (0.35,1.4);
220 \fi% monocle
221 %
222 \fi% end showing details only for front
223 %
224 % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
225 \UseHook{tikzlings/sheep/body}
226 \UseHook{tikzlings/body}
227 \csname sheephookbody\endcsname
228 \csname tikzlinghookbody\endcsname
229 %
230 }
231
232 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
233 %%
234 %% Documentation
235 %%
236 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
237 %\clearpage
238 %\section[Sheep]{Mókollur, the sheep}
239 %
240 %\emph{The sheep was kindly contributed by @Plergux. Mókollur is a bit silly and likes to goof off. This sheep's favourite food are boiled potatoes.}
241 %
242 %\subsection{Package name}
243 %
244 %\begin{tcolorbox}[title={Package usage}]
245 %\begin{samcode}
246 %\usepackage{tikzlings-sheep}
247 %\end{samcode}
248 %\end{tcolorbox}
249 %
250 %\subsection{Basic Usage}
251 %
252 %\begin{tcblisting}{title={Basic sheep}}
253 %\sheep
254 %\end{tcblisting}
255 %
256 %\subsection{Options}
257 %
258 %The basic sheep can be modified by changing its colour:
259 %\begin{tcblisting}{title={Body colour}}
260 %\sheep[body=blue]
261 %\end{tcblisting}
262 %
263 %In addition to the colour of the body, the colour of various body parts can be adjusted:
264 %\begin{tcblisting}{title={Eye colour}}
265 %\sheep[eyes=red]
266 %\end{tcblisting}
267 %\begin{tcblisting}{title={Nose colour}}
268 %\sheep[nose=red]
269 %\end{tcblisting}
270 %
271 %The sheep can also blush
272 %\begin{tcblisting}{title={Blushing sheep}}
273 %\sheep[blush=red]
274 %\end{tcblisting}
275 %
276 %and put on a monocle
277 %\begin{tcblisting}{title={Monocle}}
278 %\sheep[monocle]
279 %\end{tcblisting}
280 %
281 %To view the sheep from behind:
282 %\begin{tcblisting}{title={Back view}}
283 %\sheep[back]
284 %\end{tcblisting}
285 %
286 %The key \saminline|3D| will make the sheep 3-dimensional:
287 %\begin{tcblisting}{title={3D view}}
288 %\sheep[3D]
289 %\end{tcblisting}
290 %
291 %And finally the \saminline|contour| key will only draw the outlines:
292 %\begin{tcblisting}{title={Contours}}
293 %\sheep[contour=black]
294 %\end{tcblisting}