Debian Codegraph @

texmf-dist/source/latex/wargame/chit/dice.dtx

raw
1 % \iffalse
2 % <*chit>
3 % --------------------------------------------------------------------
4 % \fi
5 % \subsubsection{Dice}
6 %
7 % First, a regular 6-sided dice with configurable number of dots. Use
8 % like
9 %
10 % \begin{Syntax}
11 % \cs{pic}\oarg{pic options}\{dice=\meta{eyes}\}
12 % \end{Syntax}
13 %
14 % For example:
15 %
16 % \begin{enumerate}
17 % \item \tikz{\pic[transform shape]{dice=1};}
18 % \item \tikz{\pic[transform shape]{dice=2};}
19 % \item \tikz{\pic[transform shape]{dice=3};}
20 % \item \tikz{\pic[transform shape]{dice=4};}
21 % \item \tikz{\pic[transform shape]{dice=5};}
22 % \item \tikz{\pic[transform shape]{dice=6};}
23 % \end{enumerate}
24 %
25 % \begin{macrocode}
26 \tikzset{
27 dice bg/.style={
28 % /utils/exec={
29 % \pgfgettransformentries{%
30 % \wg@jaca}{%
31 % \wg@jacb}{%
32 % \wg@jacc}{%
33 % \wg@jacd}{%
34 % \wg@tmp}{%
35 % \wg@tmp}%
36 % \pgfmathsetmacro{\wg@tmp}{%
37 % sqrt(abs(\wg@jaca*\wg@jacd-\wg@jacb*\wg@jacc))}
38 % \xdef\wg@tmp{\wg@tmp}},%
39 fill=black,
40 draw=none,
41 minimum width=1cm,
42 minimum height=1cm,
43 scale rounded corners,
44 rounded corners=.1cm,
45 inner sep=0pt,
46 transform shape},
47 dice fg/.style={
48 fill=white,
49 shape=circle,
50 inner sep=0pt,
51 minimum size=.2cm,
52 transform shape},
53 pics/dice/.style={
54 code={
55 \node[dice bg] (dice bg) {};
56 \ifodd#1\node[dice fg] at (dice bg) {};\fi
57 \ifnum#1>1%
58 \node[dice fg] at ($(dice bg)+(-45:.4)$){};%
59 \node[dice fg] at ($(dice bg)+(135:.4)$){};%
60 \fi%
61 \ifnum#1>3%
62 \node[dice fg] at ($(dice bg)+( 45:.4)$){};%
63 \node[dice fg] at ($(dice bg)+(-135:.4)$){};%
64 \fi%
65 \ifnum#1=6%
66 \node[dice fg] at ($(dice bg)+(-.282,0)$){};
67 \node[dice fg] at ($(dice bg)+( .282,0)$){};
68 \fi
69 }
70 },
71 pics/dice/.default=3
72 }
73 \newcommand\dicemark[2][scale=.5]{%
74 \tikz[baseline={($(dice bg.south east)!.25!(dice bg.north east)$)},#1]{
75 \pic[transform shape]{dice=3};}}
76 % \end{macrocode}
77 %
78 % Now some shapes of different dice. This was originally done by
79 % \href{https://tex.stackexchange.com/questions/144193/how-do-i-put-a-die-roll-at-the-top-of-each-page#answer-144474}{David
80 % Carlisle}. Usage is for example
81 %
82 % \begin{Syntax}
83 % \cs{node}[shape=\meta{dice},\meta{node options}] \marg{value};
84 % \end{Syntax}
85 %
86 % where \meta{dice} is one of \texttt{d4}, \texttt{d6}, \texttt{d8},
87 % \texttt{d10}, \texttt{d12}, or \texttt{d20}.
88 %
89 % \def\DiceExample#1{%
90 % \begin{tikzpicture}[
91 % die/.style={
92 % shape=#1,
93 % scale line widths,
94 % line width=1pt,
95 % transform shape,
96 % scale=.7
97 % },
98 % fg die/.style={
99 % die,
100 % fill=##1,
101 % draw=gray!25!white,
102 % text=white},
103 % die shadow/.style={
104 % die,
105 % fill=black,
106 % draw=none,
107 % opacity=.5}]
108 % \node[die shadow,rotate=10] at (.20,.07){};
109 % \node[fg die=red,rotate=10] at (.15,.10){};
110 % \node[die shadow,rotate=-10] at (-.08,-.11){};
111 % \node[fg die=blue,rotate=-10] at (-.15,-.1){};
112 % \draw(-.5,-.5)rectangle(.6,.5);
113 % \end{tikzpicture}
114 % }
115 %
116 % \paragraph{Tetrahedron}
117 %
118 % \DiceExample{d4}
119 %
120 % \begin{macrocode}
121 \pgfdeclareshape{d4}{
122 \anchor{center}{\pgfpointorigin} % within the node, (0,0) is the center
123 \anchor{text}{
124 % this is used to center the text in the node
125 \pgfpoint{-.5\wd\pgfnodeparttextbox}{-.5\ht\pgfnodeparttextbox}}
126 \backgroundpath{ % draw border
127 \pgfpathmoveto{\pgfpoint{0cm}{.4cm}}
128 \pgfpathlineto{\pgfpoint{.433cm}{-.35cm}}
129 \pgfpathlineto{\pgfpoint{-.433cm}{-.35cm}}
130 \pgfpathlineto{\pgfpoint{0cm}{.4cm}}
131 % \pgfusepath{draw} %draw border
132 % \pgfusepath{draw} %draw rectangle
133 }}
134 % \end{macrocode}
135 %
136 % \paragraph{Cubic}
137 %
138 % \DiceExample{d6}
139 %
140 % \begin{macrocode}
141 \newif\ifwg@dsixdot\wg@dsixdotfalse
142 \tikzset{
143 d6 dots/.is if=wg@dsixdot,
144 d6 dots/.initial=false,
145 d6 dots/.default=true
146 }
147 \pgfdeclareshape{d6}{
148 \anchor{center}{\pgfpointorigin} % within the node, (0,0) is the center
149 \anchor{text}{
150 % this is used to center the text in the node
151 \pgfpoint{-.5\wd\pgfnodeparttextbox}{-.5\ht\pgfnodeparttextbox}}
152 \backgroundpath{ % draw border
153 \pgfpathrectanglecorners{\pgfpoint{.4cm}{.4cm}}{\pgfpoint{-.4cm}{-.4cm}}
154 % \pgfusepath{draw} %draw rectangle
155 }
156 \behindforegroundpath{ % draw border
157 \ifwg@dsixdot%
158 \edef\numdots{\tikz@node@content}%
159 % Draw over text
160 \pgfpathrectanglecorners{\pgfpoint{.4cm}{.4cm}}{\pgfpoint{-.4cm}{-.4cm}}%
161 \pgfusepath{fill} %draw rectangle
162 \ifx\tikz@textcolor\pgfutilempty%
163 \pgfutil@colorlet{.}{pgfstrokecolor}%
164 \else
165 % \pgfsetfillcolor{\tikz@textcolor}%
166 \pgfutil@colorlet{.}{\tikz@textcolor}%
167 \fi
168 \pgfsetfillcolor{.}%
169 \ifodd\numdots
170 %\message{^^JCenter dot}
171 \pgfpathcircle{\pgfpoint{0cm}{0cm}}{.09cm}
172 \fi
173 \ifnum\numdots=2%
174 %\message{^^JSpecial 2}
175 \pgfpathcircle{\pgfpointpolar{-45}{.32cm}}{.09cm}
176 \pgfpathcircle{\pgfpointpolar{135}{.32cm}}{.09cm}
177 \fi%
178 \ifnum\numdots>2%
179 %\message{^^JAt least 2}
180 \pgfpathcircle{\pgfpointpolar{-45}{.35cm}}{.09cm}
181 \pgfpathcircle{\pgfpointpolar{135}{.35cm}}{.09cm}
182 \fi%
183 \ifnum\numdots>3%
184 %\message{^^JAt least 4}
185 \pgfpathcircle{\pgfpointpolar{ 45}{.35cm}}{.09cm}
186 \pgfpathcircle{\pgfpointpolar{-135}{.35cm}}{.09cm}
187 \fi%
188 \ifnum\numdots=6%
189 %\message{^^JLucky 6}
190 \pgfpathcircle{\pgfpoint{-.247cm}{0cm}}{.09cm}
191 \pgfpathcircle{\pgfpoint{ .247cm}{0cm}}{.09cm}
192 \fi
193 \pgfusepath{fill} %draw rectangle
194 \fi%
195 }
196 }
197 % \end{macrocode}
198 %
199 % \paragraph{Octahedron}
200 %
201 % \DiceExample{d8}
202 %
203 % \begin{macrocode}
204 \pgfdeclareshape{d8}{
205 \anchor{center}{\pgfpointorigin} % within the node, (0,0) is the center
206 \anchor{text}{
207 % this is used to center the text in the node
208 \pgfpoint{-.5\wd\pgfnodeparttextbox}{-.5\ht\pgfnodeparttextbox}}
209 \backgroundpath{ % draw border
210 \pgfpathmoveto{\pgfpoint{0cm}{.5cm}}
211 \pgfpathlineto{\pgfpoint{.433cm}{.25cm}}
212 \pgfpathlineto{\pgfpoint{.433cm}{-.25cm}}
213 \pgfpathlineto{\pgfpoint{0cm}{-.5cm}}
214 \pgfpathlineto{\pgfpoint{-.433cm}{-.25cm}}
215 \pgfpathlineto{\pgfpoint{-.433cm}{.25cm}}
216 \pgfpathlineto{\pgfpoint{0cm}{.5cm}}
217 \pgfpathlineto{\pgfpoint{.433cm}{-.25cm}}
218 \pgfpathlineto{\pgfpoint{-.433cm}{-.25cm}}
219 \pgfpathlineto{\pgfpoint{0cm}{.5cm}}
220 % \pgfusepath{draw} %draw interiaor
221 }}
222 % \end{macrocode}
223 %
224 % \paragraph{Decahedron}
225 %
226 % \DiceExample{d10}
227 %
228 % \begin{macrocode}
229 \pgfdeclareshape{d10}{
230 \anchor{center}{\pgfpointorigin} % within the node, (0,0) is the center
231 \anchor{text}{
232 % this is used to center the text in the node
233 \pgfpoint{-.5\wd\pgfnodeparttextbox}{-.5\ht\pgfnodeparttextbox}}
234 \backgroundpath{ % draw border
235 \pgfpathmoveto{\pgfpoint{0cm}{.5cm}}
236 \pgfpathlineto{\pgfpoint{.294cm}{-.154cm}}
237 \pgfpathlineto{\pgfpoint{0cm}{-.3cm}}
238 \pgfpathlineto{\pgfpoint{-.294cm}{-.154cm}}
239 \pgfpathlineto{\pgfpoint{0cm}{.5cm}}
240 \pgfpathlineto{\pgfpoint{.475cm}{.1cm}}
241 \pgfpathlineto{\pgfpoint{.475cm}{-.1cm}}
242 \pgfpathlineto{\pgfpoint{0cm}{-.5cm}}
243 \pgfpathlineto{\pgfpoint{-.475cm}{-.1cm}}
244 \pgfpathlineto{\pgfpoint{-.475cm}{.1cm}}
245 \pgfpathlineto{\pgfpoint{0cm}{.5cm}}
246 \pgfpathmoveto{\pgfpoint{.294cm}{-.154cm}}
247 \pgfpathlineto{\pgfpoint{.475cm}{-.1cm}}
248 \pgfpathmoveto{\pgfpoint{-.475cm}{-.1cm}}
249 \pgfpathlineto{\pgfpoint{-.294cm}{-.154cm}}
250 \pgfpathmoveto{\pgfpoint{0cm}{-.5cm}}
251 \pgfpathlineto{\pgfpoint{0cm}{-.3cm}}
252 % \pgfusepath{draw} %draw interiaor
253 }}
254 % \end{macrocode}
255 %
256 % \paragraph{Dodecahedron}
257 %
258 % \DiceExample{d12}
259 %
260 % \begin{macrocode}
261 \pgfdeclareshape{d12}{
262 \anchor{center}{\pgfpointorigin} % within the node, (0,0) is the center
263 \anchor{text}{ % this is used to center the text in the node
264 \pgfpoint{-.5\wd\pgfnodeparttextbox}{-.5\ht\pgfnodeparttextbox}}
265 \backgroundpath{ % draw border
266 \pgfpathmoveto{\pgfpoint{0cm}{.5cm}}
267 \pgfpathlineto{\pgfpoint{0.294cm}{.405cm}}
268 \pgfpathlineto{\pgfpoint{.475cm}{.173cm}}
269 \pgfpathlineto{\pgfpoint{.475cm}{-.173cm}}
270 \pgfpathlineto{\pgfpoint{.294cm}{-.405cm}}
271 \pgfpathlineto{\pgfpoint{0cm}{-.5cm}}
272 \pgfpathlineto{\pgfpoint{-.294cm}{-.405cm}}
273 \pgfpathlineto{\pgfpoint{-.475cm}{-.173cm}}
274 \pgfpathlineto{\pgfpoint{-.475cm}{.173cm}}
275 \pgfpathlineto{\pgfpoint{-.294cm}{.405cm}}
276 \pgfpathlineto{\pgfpoint{0cm}{.5cm}}
277 \pgfpathlineto{\pgfpoint{0cm}{.349cm}}
278 \pgfpathlineto{\pgfpoint{.332cm}{.108cm}}
279 \pgfpathlineto{\pgfpoint{.205cm}{-.282cm}}
280 \pgfpathlineto{\pgfpoint{-.205cm}{-.282cm}}
281 \pgfpathlineto{\pgfpoint{-.332cm}{.108cm}}
282 \pgfpathlineto{\pgfpoint{0cm}{.349cm}}
283 \pgfpathmoveto{\pgfpoint{.475cm}{.173cm}}
284 \pgfpathlineto{\pgfpoint{.332cm}{.108cm}}
285 \pgfpathmoveto{\pgfpoint{.294cm}{-.405cm}}
286 \pgfpathlineto{\pgfpoint{.205cm}{-.282cm}}
287 \pgfpathmoveto{\pgfpoint{-.294cm}{-.405cm}}
288 \pgfpathlineto{\pgfpoint{-.205cm}{-.282cm}}
289 \pgfpathmoveto{\pgfpoint{-.475cm}{.173cm}}
290 \pgfpathlineto{\pgfpoint{-.332cm}{.108cm}}
291 % \pgfusepath{draw} %draw interiaor
292 }}
293 % \end{macrocode}
294 %
295 % \paragraph{Icosohedron}
296 %
297 % \DiceExample{d20}
298 %
299 % \begin{macrocode}
300 \pgfdeclareshape{d20}{
301 \anchor{center}{\pgfpointorigin} % within the node, (0,0) is the center
302 \anchor{text}{ % this is used to center the text in the node
303 \pgfpoint{-.5\wd\pgfnodeparttextbox}{-.5\ht\pgfnodeparttextbox}}
304 \backgroundpath{ % draw border
305 \pgfpathmoveto{\pgfpoint{0cm}{.5cm}}
306 \pgfpathlineto{\pgfpoint{.454cm}{.262cm}}
307 \pgfpathlineto{\pgfpoint{.454cm}{-.262cm}}
308 \pgfpathlineto{\pgfpoint{0cm}{-.5cm}}
309 \pgfpathlineto{\pgfpoint{-.454cm}{-.262cm}}
310 \pgfpathlineto{\pgfpoint{-.454cm}{.262cm}}
311 \pgfpathlineto{\pgfpoint{0cm}{.5cm}}
312 \pgfpathlineto{\pgfpoint{0cm}{.292cm}}
313 \pgfpathlineto{\pgfpoint{.253cm}{-.146cm}}
314 \pgfpathlineto{\pgfpoint{-.253cm}{-.146cm}}
315 \pgfpathlineto{\pgfpoint{0cm}{.292cm}}
316 \pgfpathlineto{\pgfpoint{.454cm}{.262cm}}
317 \pgfpathlineto{\pgfpoint{.253cm}{-.146cm}}
318 \pgfpathlineto{\pgfpoint{0cm}{-.5cm}}
319 \pgfpathlineto{\pgfpoint{-.253cm}{-.146cm}}
320 \pgfpathlineto{\pgfpoint{-.454cm}{.262cm}}
321 \pgfpathlineto{\pgfpoint{0cm}{.292cm}}
322 \pgfpathmoveto{\pgfpoint{.454cm}{-.262cm}}
323 \pgfpathlineto{\pgfpoint{.253cm}{-.146cm}}
324 \pgfpathmoveto{\pgfpoint{-.454cm}{-.262cm}}
325 \pgfpathlineto{\pgfpoint{-.253cm}{-.146cm}}
326 % \pgfusepath{draw} %draw interiaor
327 }}
328 % \end{macrocode}
329 %
330 % \iffalse
331 % </chit>
332 % --------------------------------------------------------------------
333 % \fi