-
Notifications
You must be signed in to change notification settings - Fork 7
/
tikzlings-bats.sty
260 lines (254 loc) · 10.4 KB
/
tikzlings-bats.sty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
% !TeX root = ./examples/bat.tex
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% This package is part of the TikZlings package
%% A package to bring cute little animals and other beings into tikz
%% Maintained by samcarter
%%
%% Project repository and bug tracker:
%% https://github.com/samcarter/tikzlings
%%
%% Released under the LaTeX Project Public License v1.3c or later
%% See https://www.latex-project.org/lppl.txt
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\ProvidesPackage{tikzlings-bats}[2022/06/17 version v1.0 Drawing bats in TikZ]
\RequirePackage{tikz}
\RequirePackage{tikzlings-addons}
\newcommand*{\bat}[1][]{%
\begin{scope}%
\tikzset{/bat/.cd,#1}%
\bat@draw%
\end{scope}%
\thing[#1]%
% adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\csname bathookforeground\endcsname
\csname tikzlinghookforeground\endcsname
%
}
\newif\ifbat@threeD
\newif\ifbat@back
\newif\ifbat@contour
\newif\ifbat@teeth
\tikzset{
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Pass unknown keys on to tikz
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
/bat/.search also={/tikz,/pgf,/thing},
/bat/.cd,
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% body
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
body/.store in = \bat@body,
body = black!75!white,
ears/.store in = \bat@ears,
ears = \bat@body,
eye/.store in = \bat@eye,
eye = white,
pupil/.store in = \bat@pupil,
pupil = black,
mouth/.store in = \bat@mouth,
mouth = black,
feet/.store in = \bat@feet,
feet = orange,
wings/.store in = \bat@wings,
wings = 1,
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% options
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
teeth/.code = \bat@teethtrue
\def\bat@teeth{#1},
teeth/.default = white,
3D/.code = \bat@threeDtrue,
back/.code = \bat@backtrue,
contour/.code = \bat@contourtrue
\def\bat@contour{#1}
\def\bat@antennas{#1}
\def\bat@mouth{#1},
contour/.default = black,
outline/.forward to = /bat/contour,
}
\def\bat@draw{%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% minimal bounding box size
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\path (-0.44,0.0) rectangle (0.44, 2.2);
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% store the current scale factor
% from https://github.com/samcarter/tikzlings/issues/3#issuecomment-461373494
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pgfgettransformentries{\tmpscaleA}{\tmpscaleB}{\tmpscaleC}{\tmpscaleD}{\tmp}{\tmp}%
\pgfmathsetmacro{\scalingfactor}{sqrt(abs(\tmpscaleA*\tmpscaleD-\tmpscaleB*\tmpscaleC))*sqrt(abs((\pgf@xx/1cm)*(\pgf@yy/1cm)-(\pgf@xy/1cm)*(\pgf@yx/1cm)))}%
\pgfmathsetmacro{\xscalefactor}{\tmpscaleA}
\pgfmathsetmacro{\yscalefactor}{\tmpscaleD}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% switch between 2D, 3D and contours, from
% https://chat.stackexchange.com/transcript/message/45991801#45991801
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\ifbat@threeD
\def\bat@part@draw[##1]{\shade[ball color=##1]}
\else% 3D
\ifbat@contour
\def\bat@part@draw[##1]{\draw[##1,\bat@contour,fill=white,line width=\scalingfactor*0.4pt]}
\else% contour
\def\bat@part@draw[##1]{\fill[##1]}
\fi% contour
\fi% 3D
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Body parts
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\csname batshookbackground\endcsname
\csname tikzlinghookbackground\endcsname
%
% Wings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\bat@part@draw[\bat@body] (-0.4147-\bat@wings*1.8711, 0.6377) .. controls (-0.4147-\bat@wings*2.0410, 1.1512) and (-0.4147-\bat@wings*1.1342, 1.5336) .. (-0.4147-\bat@wings*0.5687, 1.6054) .. controls (-0.4147-\bat@wings*0.3860, 1.4742) and (-0.4147-\bat@wings*0.0711, 1.3009) .. (-0.35, 1.2365) -- (-0.35, 0.5586) .. controls (-0.4147-\bat@wings*0.0890, 0.6892) and (-0.4147-\bat@wings*0.2882, 0.7333) .. (-0.4147-\bat@wings*0.4758, 0.6377) .. controls (-0.4147-\bat@wings*0.6753, 0.841) and (-0.4147-\bat@wings*0.9758, 0.8349) .. (-0.4147-\bat@wings*1.1476, 0.6377) .. controls (-0.4147-\bat@wings*1.2902, 0.8407) and (-0.4147-\bat@wings*1.72, 0.8553) .. (-0.4147-\bat@wings*1.8711, 0.6377) -- cycle;
\bat@part@draw[\bat@body] (0.4147+\bat@wings*1.8711, 0.6377) .. controls (0.4147+\bat@wings*2.0410, 1.1512) and (0.4147+\bat@wings*1.1342, 1.5336) .. (0.4147+\bat@wings*0.5687, 1.6054) .. controls (0.4147+\bat@wings*0.3860, 1.4742) and (0.4147+\bat@wings*0.0711, 1.3009) .. (0.35, 1.2365) -- (0.35, 0.5586) .. controls (0.4147+\bat@wings*0.0890, 0.6892) and (0.4147+\bat@wings*0.2882, 0.7333) .. (0.4147+\bat@wings*0.4758, 0.6377) .. controls (0.4147+\bat@wings*0.6753, 0.841) and (0.4147+\bat@wings*0.9758, 0.8349) .. (0.4147+\bat@wings*1.1476, 0.6377) .. controls (0.4147+\bat@wings*1.2902, 0.8407) and (0.4147+\bat@wings*1.72, 0.8553) .. (0.4147+\bat@wings*1.8711, 0.6377) -- cycle;
%
% Ears %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\bat@part@draw[\bat@ears] (-0.3498, 1.7392) .. controls (-0.3498, 1.7392) and (-0.4724, 1.9226) .. (-0.3896, 2.177) .. controls (-0.2561, 2.2679) and (-0.0953, 1.9447) .. (0.0234, 1.9394) -- cycle;
\bat@part@draw[\bat@ears] (0.3498, 1.7392) .. controls (0.3498, 1.7392) and (0.4724, 1.9226) .. (0.3896, 2.177) .. controls (0.2561, 2.2679) and (0.0953, 1.9447) .. (-0.0234, 1.9394) -- cycle;
%
% Feet %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\ifbat@back
\bat@part@draw[\bat@feet] (0.175,0.1) ellipse[x radius=0.03, y radius=0.1];
\bat@part@draw[\bat@feet] (0.225,0.11) ellipse[x radius=0.03, y radius=0.1, rotate=20];
\bat@part@draw[\bat@feet] (0.275,0.13) ellipse[x radius=0.03, y radius=0.1, rotate=40];
\bat@part@draw[\bat@feet] (-0.175,0.1) ellipse[x radius=0.03, y radius=0.1];
\bat@part@draw[\bat@feet] (-0.225,0.11) ellipse[x radius=0.03, y radius=0.1, rotate=-20];
\bat@part@draw[\bat@feet] (-0.275,0.13) ellipse[x radius=0.03, y radius=0.1, rotate=-40];
\fi% back
%
% Body %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\bat@part@draw[\bat@body] (0,0.8) ellipse [y radius=0.7, x radius=0.45];
%
% Head %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\bat@part@draw[\bat@body] (0,1.55) circle [radius=0.43];
%
% adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\csname batshookbelly\endcsname
\csname tikzlinghookbelly\endcsname
%
% Show details only from the front %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\unless\ifbat@back
%
% Feet %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\bat@part@draw[\bat@feet] (0.175,0.1) ellipse[x radius=0.03, y radius=0.1];
\bat@part@draw[\bat@feet] (0.225,0.11) ellipse[x radius=0.03, y radius=0.1, rotate=20];
\bat@part@draw[\bat@feet] (0.275,0.13) ellipse[x radius=0.03, y radius=0.1, rotate=40];
\bat@part@draw[\bat@feet] (-0.175,0.1) ellipse[x radius=0.03, y radius=0.1];
\bat@part@draw[\bat@feet] (-0.225,0.11) ellipse[x radius=0.03, y radius=0.1, rotate=-20];
\bat@part@draw[\bat@feet] (-0.275,0.13) ellipse[x radius=0.03, y radius=0.1, rotate=-40];
%
% Eyes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\bat@part@draw[\bat@eye] (-0.18,1.66) ellipse[x radius=0.1, y radius=0.15, rotate=10];
\bat@part@draw[\bat@pupil] (-0.15,1.645) ellipse[x radius=0.0357, y radius=0.0714, rotate=3];
\bat@part@draw[\bat@eye] (0.18,1.66) ellipse[x radius=0.1, y radius=0.15, rotate=-10];
\bat@part@draw[\bat@pupil] (0.15,1.645) ellipse[x radius=0.0357, y radius=0.0714, rotate=-3];
%
% Teeth %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\ifbat@teeth
\bat@part@draw[\bat@teeth] (-0.1,1.36) -- (-0.12,1.3) -- (-0.14,1.38) -- cycle;
\bat@part@draw[\bat@teeth] (0.1,1.36) -- (0.12,1.3) -- (0.14,1.38) -- cycle;
\fi
%
% Mouth %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\draw[\bat@mouth,line width=\scalingfactor*0.4pt] (0.18, 1.42) arc [start angle=-40, end angle=-140, radius=0.23];
%
%
\fi% back
% adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\csname batshookbody\endcsname
\csname tikzlinghookbody\endcsname
%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% Documentation
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\clearpage
%\section[Bat]{Natalie, the bat}
%
%\emph{Named after a dear friend from my undergrad studies}
%
%\subsection{Package name}
%
%\begin{tcolorbox}
%\begin{samcode}
%\usepackage{tikzlings-bats}
%\end{samcode}
%\end{tcolorbox}
%
%\subsection{Basic Usage}
%
%\begin{tcblisting}{}
%\bat
%\end{tcblisting}
%
%\subsection{Options}
%
%The basic bat can be modified by changing its colour:
%\begin{tcblisting}{}
%\bat[body=blue]
%\end{tcblisting}
%
%In addition to the colour of the body, the colour of various body parts can be adjusted:
%\begin{tcblisting}{}
%\bat[eye=red]
%\end{tcblisting}
%\begin{tcblisting}{}
%\bat[pupil=red]
%\end{tcblisting}
%\begin{tcblisting}{}
%\bat[mouth=red]
%\end{tcblisting}
%\begin{tcblisting}{}
%\bat[ears=red]
%\end{tcblisting}
%\begin{tcblisting}{}
%\bat[feet=red]
%\end{tcblisting}
%
%The spread of the wings can be adjusted by passing values between 0 and 1 to the \saminline|wings| option:
%\begin{tcblisting}{}
%\bat[wings=0.5]
%\end{tcblisting}
%
%To turn the bat into a vampire bat, the \saminline|teeth| option can be used:
%\begin{tcblisting}{}
%\bat[teeth=white]
%\end{tcblisting}
%
%To view the bat from behind:
%\begin{tcblisting}{}
%\bat[back]
%\end{tcblisting}
%
%The key \saminline|3D| will make the bat 3-dimensional:
%\begin{tcblisting}{}
%\bat[3D]
%\end{tcblisting}
%
%And finally the \saminline|contour| key will only draw the outlines:
%\begin{tcblisting}{}
%\bat[contour=black]
%\end{tcblisting}