summaryrefslogtreecommitdiff
path: root/graphics/pgf/contrib/tikzlings/tikzlings-snowmen.sty
blob: 5b5f8513521da1af2bf38ebe32fb3660cfd6601a (plain)
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
261
262
263
264
265
266
267
268
269
270
271
 % !TeX root = ./examples/snowman.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 http://www.latex-project.org/lppl.txt
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\ProvidesPackage{tikzlings-snowmen}[2021/08/06 version v0.8 Draw snowmen in TikZ]

\RequirePackage{tikz}
\RequirePackage{tikzlings-addons}

\newcommand*{\snowman}[1][]{%
  \begin{scope}%
    \tikzset{/snowman/.cd,#1}%
    \snowman@draw%
  \end{scope}%
  \thing[#1]%
  % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \csname snowmanhookforeground\endcsname
  \csname tikzlinghookforeground\endcsname
  %  
}

\newif\ifsnowman@threeD
\newif\ifsnowman@back
\newif\ifsnowman@globalwarming
\newif\ifsnowman@contour

\tikzset{
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % Pass unknown keys on to tikz
  %
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  /snowman/.search also={/tikz,/pgf,/thing},
  /snowman/.cd,
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % body
  %
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  body/.code         = \def\snowman@body{#1},
  body               = white!95!black,
  eye/.code          = \def\snowman@eye{#1},
  eye                = black,
  nose/.code         = \def\snowman@nose{#1},
  nose               = orange,
  mouth/.code        = \def\snowman@mouth{#1},
  mouth              = black,
  buttons/.code      = \def\snowman@buttons{#1},
  buttons            = black, 
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % options
  %
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3D/.code           = \snowman@threeDtrue, 
  back/.code         = \snowman@backtrue,
  globalwarming/.code= \snowman@globalwarmingtrue
                       \def\snowman@globalwarming{#1},
  globalwarming/.default = blue!10!white,                       
  global warming/.forward to = /snowman/globalwarming,
  contour/.code      = \snowman@contourtrue
                       \def\snowman@contour{#1}
                       \def\snowman@mouth{#1},
  contour/.default   = black,  
  outline/.forward to = /snowman/contour,  
}

\def\snowman@draw{%
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % minimal bounding box size 
  %
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \path (-0.75, 0.0) rectangle (0.75, 2.13);
  %
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % 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
  %
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \ifsnowman@threeD
    \def\snowman@part@draw[##1]{\shade[ball color=##1]}
  \else% 3D
    \ifsnowman@contour
      \def\snowman@part@draw[##1]{\draw[##1,\snowman@contour,fill=white,line width=\scalingfactor*0.4pt]}
    \else% contour
      \def\snowman@part@draw[##1]{\fill[##1]}
    \fi% contour
  \fi% 3D
  %
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % Body parts
  % 
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \csname snowmanhookbackground\endcsname
  \csname tikzlinghookbackground\endcsname
  %
  % Global warming %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \ifsnowman@globalwarming
    %
    % Puddle %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \ifsnowman@contour
      \draw[\snowman@contour,fill=white,line width=\scalingfactor*0.4pt] (0,1.15) ellipse[x radius=1.6,y radius=1.15];
    \else% contour
      \fill[\snowman@globalwarming] (0,1.15) ellipse[x radius=1.6,y radius=1.15];
    \fi% contour
    %
    % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \csname snowmanhookbelly\endcsname
    \csname tikzlinghookbelly\endcsname
    %
    % Mouth %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \fill[\snowman@mouth] (0,1.23) circle[radius=0.025]; 
    \fill[\snowman@mouth] (0.06,1.3) circle[radius=0.025];  
    \fill[\snowman@mouth] (-0.06,1.27) circle[radius=0.025];  
    \fill[\snowman@mouth] (0.09,1.37) circle[radius=0.025];  
    \fill[\snowman@mouth] (-0.18,1.28) circle[radius=0.025];  
    \fill[\snowman@mouth] (0.2,1.28) circle[radius=0.025];  
    \fill[\snowman@mouth] (-0.25,1.2) circle[radius=0.025];
    %
    % Eyes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \snowman@part@draw[\snowman@eye] (-0.5,1.75) circle[radius=0.06]; 
    \snowman@part@draw[\snowman@eye] (-0.1,1.55) circle[radius=0.06]; 
    %
    % Nose %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \snowman@part@draw[\snowman@nose] (-0.6,1.4) -- (-0.8,1.42) -- (-0.6,1.54) (-0.6,1.4) arc[radius=0.07, start angle=-90, end angle=90];  
    %
    % Buttons %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \snowman@part@draw[\snowman@buttons] (0.1,0.8) circle[radius=0.06];
    \snowman@part@draw[\snowman@buttons] (-0.15,0.55) circle[radius=0.06];
    \snowman@part@draw[\snowman@buttons] (0,0.25) circle[radius=0.06];   
  %
  % normal snowman %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \else% global warming
    %
    % Arms %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \snowman@part@draw[\snowman@body] (0.5,1.1) ellipse[x radius=0.3, y radius=0.12, rotate=-50];
    \snowman@part@draw[\snowman@body] (-0.5,1.1) ellipse[x radius=0.3, y radius=0.12, rotate=50];
    %
    % Body + Head %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \snowman@part@draw[\snowman@body] (0,0.5) ellipse[x radius=0.6, y radius=0.5];
    \snowman@part@draw[\snowman@body] (0,1.1) ellipse[x radius=0.5, y radius=0.4];
    \snowman@part@draw[\snowman@body] (0,1.7) circle[radius=0.4];  
    %
    % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \csname snowmanhookbelly\endcsname
    \csname tikzlinghookbelly\endcsname
    %
    % Show details only from the front %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \unless\ifsnowman@back
      %
      % Mouth% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      \fill[\snowman@mouth] (0,1.5) circle[radius=0.016];
      \fill[\snowman@mouth] (0.04,1.507) circle[radius=0.016];
      \fill[\snowman@mouth] (-0.04,1.507) circle[radius=0.016];
      \fill[\snowman@mouth] (0.08,1.522) circle[radius=0.016];
      \fill[\snowman@mouth] (-0.08,1.522) circle[radius=0.016];
      \fill[\snowman@mouth] (0.12,1.543) circle[radius=0.016];
      \fill[\snowman@mouth] (-0.12,1.543) circle[radius=0.016];
      %
      % Eyes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      \snowman@part@draw[\snowman@eye] (-0.155,1.8) circle[radius=0.04]; 
      \snowman@part@draw[\snowman@eye] (0.155,1.8) circle[radius=0.04]; 
      %
      % Nose %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      \snowman@part@draw[\snowman@nose] (0,1.72) arc [radius=0.05, start angle=90, end angle=270] (0,1.62) -- (0.15,1.64) -- (0,1.72);
      %
      % Buttons %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      \snowman@part@draw[\snowman@buttons] (0,1.15) circle[radius=0.04]; 
      \snowman@part@draw[\snowman@buttons] (0,0.95) circle[radius=0.04]; 
      \snowman@part@draw[\snowman@buttons] (0,0.75) circle[radius=0.04]; 
      %
    \fi% back
  %
  \fi% global warming
  %
  % adding hook for users to customise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \csname snowmanhookbody\endcsname
  \csname tikzlinghookbody\endcsname
  %
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% Documentation
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\clearpage
%\section[Snowman]{Yuki, the snowman}
%
%\emph{Yuki is the transcription of the Japanese word for snow}
%
%\subsection{Package name}
%
%\begin{tcolorbox}[lower separated=false, lefthand width=.8\linewidth]
%\vspace*{0.5cm}
%\lstinline|\usepackage{tikzlings-snowmen}| 
%\vspace*{0.5cm}
%\end{tcolorbox}
%
%\subsection{Basic Usage}
%
%\begin{tcblisting}{}
%\snowman
%\end{tcblisting}
%
%\subsection{Options}
%
%The basic snowman can be modified by changing its colour:
%\begin{tcblisting}{}
%\snowman[body=blue]
%\end{tcblisting}
%
%In addition to the colour of the body, the colour of various body parts can be adjusted:
%\begin{tcblisting}{}
%\snowman[eye=red]
%\end{tcblisting}
%\begin{tcblisting}{}
%\snowman[nose=red]
%\end{tcblisting}
%\begin{tcblisting}{}
%\snowman[mouth=red]
%\end{tcblisting}
%\begin{tcblisting}{}
%\snowman[buttons=red]
%\end{tcblisting}
%
%The biggest enemy of the snowman are raising temperatures:
%\begin{tcblisting}{}
%\snowman[globalwarming,tophat]
%\end{tcblisting}
%
%To view the snowman from behind:
%\begin{tcblisting}{}
%\snowman[back]
%\end{tcblisting}
%
%The key \lstinline|3D| will make the snowman 3-dimensional:
%\begin{tcblisting}{}
%\snowman[3D]
%\end{tcblisting}
%
%And finally the \lstinline|contour| key will only draw the outlines:
%\begin{tcblisting}{}
%\snowman[contour=black]
%\end{tcblisting}