summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/wargame/source/chit/dice.dtx
blob: 0c07c91d4f3edd7e86ceb184ab6a0e627ddbe743 (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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
% \iffalse
% <*chit>
% --------------------------------------------------------------------
% \fi
% \subsubsection{Dice}
%
% First, a regular 6-sided dice with configurable number of dots. Use
% like 
%
%   \begin{Syntax}
%     \cs{pic}\oarg{pic options}\{dice=\meta{eyes}\}
%   \end{Syntax}
% 
% For example:
%
% \begin{enumerate}
% \item \tikz{\pic[transform shape]{dice=1};}
% \item \tikz{\pic[transform shape]{dice=2};}
% \item \tikz{\pic[transform shape]{dice=3};}
% \item \tikz{\pic[transform shape]{dice=4};}
% \item \tikz{\pic[transform shape]{dice=5};}
% \item \tikz{\pic[transform shape]{dice=6};}
% \end{enumerate}
%
%    \begin{macrocode}
\tikzset{
  dice bg/.style={
    % /utils/exec={
    %   \pgfgettransformentries{%
    %     \wg@jaca}{%
    %     \wg@jacb}{%
    %     \wg@jacc}{%
    %     \wg@jacd}{%
    %     \wg@tmp}{%
    %     \wg@tmp}%
    %   \pgfmathsetmacro{\wg@tmp}{%
    %     sqrt(abs(\wg@jaca*\wg@jacd-\wg@jacb*\wg@jacc))}
    %   \xdef\wg@tmp{\wg@tmp}},%
    fill=black,
    draw=none,
    minimum width=1cm,
    minimum height=1cm,
    scale rounded corners,
    rounded corners=.1cm,
    inner sep=0pt,
    transform shape},
  dice fg/.style={
    fill=white,
    shape=circle,
    inner sep=0pt,
    minimum size=.2cm,
    transform shape},
  pics/dice/.style={
    code={
      \node[dice bg] (dice bg) {};
      \ifodd#1\node[dice fg] at (dice bg) {};\fi
      \ifnum#1>1%
      \node[dice fg] at ($(dice bg)+(-45:.4)$){};%
      \node[dice fg] at ($(dice bg)+(135:.4)$){};%
      \fi%
      \ifnum#1>3%
      \node[dice fg] at ($(dice bg)+(  45:.4)$){};%
      \node[dice fg] at ($(dice bg)+(-135:.4)$){};%
      \fi%
      \ifnum#1=6%  
      \node[dice fg] at ($(dice bg)+(-.282,0)$){};
      \node[dice fg] at ($(dice bg)+( .282,0)$){};
      \fi
    }
  },
  pics/dice/.default=3
}
\newcommand\dicemark[2][scale=.5]{%
  \tikz[baseline={($(dice bg.south east)!.25!(dice bg.north east)$)},#1]{
    \pic[transform shape]{dice=3};}}
%    \end{macrocode}
% 
% Now some shapes of different dice.  This was originally done by
% \href{https://tex.stackexchange.com/questions/144193/how-do-i-put-a-die-roll-at-the-top-of-each-page#answer-144474}{David
% Carlisle}.  Usage is for example
%
% \begin{Syntax}
%   \cs{node}[shape=\meta{dice},\meta{node options}] \marg{value};
% \end{Syntax}
%
% where \meta{dice} is one of \texttt{d4}, \texttt{d6}, \texttt{d8},
% \texttt{d10}, \texttt{d12}, or \texttt{d20}. 
%
% \def\DiceExample#1{%
%   \begin{tikzpicture}[
%     die/.style={
%       shape=#1,
%       scale line widths,
%       line width=1pt,
%       transform shape,
%       scale=.7
%     },
%     fg die/.style={
%       die,
%       fill=##1,
%       draw=gray!25!white,
%       text=white},
%     die shadow/.style={
%       die,
%       fill=black,
%       draw=none,
%       opacity=.5}]
%     \node[die shadow,rotate=10] at (.20,.07){};
%     \node[fg die=red,rotate=10] at (.15,.10){};
%     \node[die shadow,rotate=-10] at (-.08,-.11){};
%     \node[fg die=blue,rotate=-10] at (-.15,-.1){};
%     \draw(-.5,-.5)rectangle(.6,.5);
%   \end{tikzpicture}
% }
%
% \paragraph{Tetrahedron}
% 
% \DiceExample{d4}
%
%    \begin{macrocode}
\pgfdeclareshape{d4}{
  \anchor{center}{\pgfpointorigin}    % within the node, (0,0) is the center
  \anchor{text}{
    % this is used to center the text in the node
    \pgfpoint{-.5\wd\pgfnodeparttextbox}{-.5\ht\pgfnodeparttextbox}}
  \backgroundpath{ % draw border
    \pgfpathmoveto{\pgfpoint{0cm}{.4cm}}
    \pgfpathlineto{\pgfpoint{.433cm}{-.35cm}}
    \pgfpathlineto{\pgfpoint{-.433cm}{-.35cm}}
    \pgfpathlineto{\pgfpoint{0cm}{.4cm}}
    % \pgfusepath{draw}  %draw border
    % \pgfusepath{draw}  %draw rectangle
  }}
%    \end{macrocode}
%    
% \paragraph{Cubic}
% 
% \DiceExample{d6}
%
%    \begin{macrocode}
\pgfdeclareshape{d6}{
  \anchor{center}{\pgfpointorigin}    % within the node, (0,0) is the center
  \anchor{text}{
    % this is used to center the text in the node
    \pgfpoint{-.5\wd\pgfnodeparttextbox}{-.5\ht\pgfnodeparttextbox}}
  \backgroundpath{ % draw border
    \pgfpathrectanglecorners{\pgfpoint{.4cm}{.4cm}}{\pgfpoint{-.4cm}{-.4cm}}
    % \pgfusepath{draw}  %draw rectangle
  }}
%    \end{macrocode}
%    
% \paragraph{Octahedron}
%
% \DiceExample{d8}
% 
%    \begin{macrocode}
\pgfdeclareshape{d8}{
  \anchor{center}{\pgfpointorigin}    % within the node, (0,0) is the center
  \anchor{text}{
    % this is used to center the text in the node
    \pgfpoint{-.5\wd\pgfnodeparttextbox}{-.5\ht\pgfnodeparttextbox}}
  \backgroundpath{ % draw border
    \pgfpathmoveto{\pgfpoint{0cm}{.5cm}}
    \pgfpathlineto{\pgfpoint{.433cm}{.25cm}}
    \pgfpathlineto{\pgfpoint{.433cm}{-.25cm}}
    \pgfpathlineto{\pgfpoint{0cm}{-.5cm}}
    \pgfpathlineto{\pgfpoint{-.433cm}{-.25cm}}
    \pgfpathlineto{\pgfpoint{-.433cm}{.25cm}}
    \pgfpathlineto{\pgfpoint{0cm}{.5cm}}
    \pgfpathlineto{\pgfpoint{.433cm}{-.25cm}}
    \pgfpathlineto{\pgfpoint{-.433cm}{-.25cm}}
    \pgfpathlineto{\pgfpoint{0cm}{.5cm}}
    % \pgfusepath{draw}  %draw interiaor
  }}
%    \end{macrocode}
%    
% \paragraph{Decahedron}
%
% \DiceExample{d10}
% 
%    \begin{macrocode}
\pgfdeclareshape{d10}{
  \anchor{center}{\pgfpointorigin}    % within the node, (0,0) is the center
  \anchor{text}{
    % this is used to center the text in the node
    \pgfpoint{-.5\wd\pgfnodeparttextbox}{-.5\ht\pgfnodeparttextbox}}
  \backgroundpath{ % draw border
    \pgfpathmoveto{\pgfpoint{0cm}{.5cm}}
    \pgfpathlineto{\pgfpoint{.294cm}{-.154cm}}
    \pgfpathlineto{\pgfpoint{0cm}{-.3cm}}
    \pgfpathlineto{\pgfpoint{-.294cm}{-.154cm}}
    \pgfpathlineto{\pgfpoint{0cm}{.5cm}}
    \pgfpathlineto{\pgfpoint{.475cm}{.1cm}}
    \pgfpathlineto{\pgfpoint{.475cm}{-.1cm}}
    \pgfpathlineto{\pgfpoint{0cm}{-.5cm}}
    \pgfpathlineto{\pgfpoint{-.475cm}{-.1cm}}
    \pgfpathlineto{\pgfpoint{-.475cm}{.1cm}}
    \pgfpathlineto{\pgfpoint{0cm}{.5cm}}
    \pgfpathmoveto{\pgfpoint{.294cm}{-.154cm}}
    \pgfpathlineto{\pgfpoint{.475cm}{-.1cm}}
    \pgfpathmoveto{\pgfpoint{-.475cm}{-.1cm}}
    \pgfpathlineto{\pgfpoint{-.294cm}{-.154cm}}
    \pgfpathmoveto{\pgfpoint{0cm}{-.5cm}}
    \pgfpathlineto{\pgfpoint{0cm}{-.3cm}}
    % \pgfusepath{draw}  %draw interiaor
  }}
%    \end{macrocode}
%    
% \paragraph{Dodecahedron}
%
% \DiceExample{d12}
% 
%    \begin{macrocode}
\pgfdeclareshape{d12}{
  \anchor{center}{\pgfpointorigin}    % within the node, (0,0) is the center
  \anchor{text}{   % this is used to center the text in the node
    \pgfpoint{-.5\wd\pgfnodeparttextbox}{-.5\ht\pgfnodeparttextbox}}
  \backgroundpath{ % draw border
    \pgfpathmoveto{\pgfpoint{0cm}{.5cm}}
    \pgfpathlineto{\pgfpoint{0.294cm}{.405cm}}
    \pgfpathlineto{\pgfpoint{.475cm}{.173cm}}
    \pgfpathlineto{\pgfpoint{.475cm}{-.173cm}}
    \pgfpathlineto{\pgfpoint{.294cm}{-.405cm}}
    \pgfpathlineto{\pgfpoint{0cm}{-.5cm}}
    \pgfpathlineto{\pgfpoint{-.294cm}{-.405cm}}
    \pgfpathlineto{\pgfpoint{-.475cm}{-.173cm}}
    \pgfpathlineto{\pgfpoint{-.475cm}{.173cm}}
    \pgfpathlineto{\pgfpoint{-.294cm}{.405cm}}
    \pgfpathlineto{\pgfpoint{0cm}{.5cm}}
    \pgfpathlineto{\pgfpoint{0cm}{.349cm}}
    \pgfpathlineto{\pgfpoint{.332cm}{.108cm}}
    \pgfpathlineto{\pgfpoint{.205cm}{-.282cm}}
    \pgfpathlineto{\pgfpoint{-.205cm}{-.282cm}}
    \pgfpathlineto{\pgfpoint{-.332cm}{.108cm}}
    \pgfpathlineto{\pgfpoint{0cm}{.349cm}}
    \pgfpathmoveto{\pgfpoint{.475cm}{.173cm}}
    \pgfpathlineto{\pgfpoint{.332cm}{.108cm}}
    \pgfpathmoveto{\pgfpoint{.294cm}{-.405cm}}
    \pgfpathlineto{\pgfpoint{.205cm}{-.282cm}}
    \pgfpathmoveto{\pgfpoint{-.294cm}{-.405cm}}
    \pgfpathlineto{\pgfpoint{-.205cm}{-.282cm}}
    \pgfpathmoveto{\pgfpoint{-.475cm}{.173cm}}
    \pgfpathlineto{\pgfpoint{-.332cm}{.108cm}}
    % \pgfusepath{draw}  %draw interiaor
  }}
%    \end{macrocode}
%    
% \paragraph{Icosohedron}
%
% \DiceExample{d20}
% 
%    \begin{macrocode}
\pgfdeclareshape{d20}{
  \anchor{center}{\pgfpointorigin} % within the node, (0,0) is the center
  \anchor{text}{    % this is used to center the text in the node
    \pgfpoint{-.5\wd\pgfnodeparttextbox}{-.5\ht\pgfnodeparttextbox}}
  \backgroundpath{ % draw border
    \pgfpathmoveto{\pgfpoint{0cm}{.5cm}}
    \pgfpathlineto{\pgfpoint{.454cm}{.262cm}}
    \pgfpathlineto{\pgfpoint{.454cm}{-.262cm}}
    \pgfpathlineto{\pgfpoint{0cm}{-.5cm}}
    \pgfpathlineto{\pgfpoint{-.454cm}{-.262cm}}
    \pgfpathlineto{\pgfpoint{-.454cm}{.262cm}}
    \pgfpathlineto{\pgfpoint{0cm}{.5cm}}
    \pgfpathlineto{\pgfpoint{0cm}{.292cm}}
    \pgfpathlineto{\pgfpoint{.253cm}{-.146cm}}
    \pgfpathlineto{\pgfpoint{-.253cm}{-.146cm}}
    \pgfpathlineto{\pgfpoint{0cm}{.292cm}}
    \pgfpathlineto{\pgfpoint{.454cm}{.262cm}}
    \pgfpathlineto{\pgfpoint{.253cm}{-.146cm}}
    \pgfpathlineto{\pgfpoint{0cm}{-.5cm}}
    \pgfpathlineto{\pgfpoint{-.253cm}{-.146cm}}
    \pgfpathlineto{\pgfpoint{-.454cm}{.262cm}}
    \pgfpathlineto{\pgfpoint{0cm}{.292cm}}
    \pgfpathmoveto{\pgfpoint{.454cm}{-.262cm}}
    \pgfpathlineto{\pgfpoint{.253cm}{-.146cm}}
    \pgfpathmoveto{\pgfpoint{-.454cm}{-.262cm}}
    \pgfpathlineto{\pgfpoint{-.253cm}{-.146cm}}
    % \pgfusepath{draw}  %draw interiaor
  }}
%    \end{macrocode}
% 
% \iffalse
% </chit>
% --------------------------------------------------------------------
% \fi