-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbingo.tex
122 lines (103 loc) · 3.49 KB
/
bingo.tex
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
\documentclass[10pt,a4paper]{article}
\usepackage[scaled]{helvet}
\renewcommand*\familydefault{\sfdefault}
\usepackage[T1]{fontenc}
\usepackage[cm]{fullpage}
\usepackage{xstring}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{xparse}
\usepackage{eso-pic}
\input{random.tex}
\newcount\randomnum
\ExplSyntaxOn
\seq_new:N \g_my_items_seq
\seq_new:N \g_tmp
\seq_new:N \l_my_tmp_items_seq
\seq_new:N \g_my_randomized_seq
\int_new:N \l_tmp_int
\tl_new:N \tl_raw
\ior_new:N \io_stream
\msg_new:nnnn {bingo} {Too~few~items!} {Provide~at~least~24~items!}{}
\cs_generate_variant:Nn \seq_item:Nn {Nx}
\cs_generate_variant:Nn \seq_remove_all:Nn {Nx}
\NewDocumentCommand {\myItems} {}
{
\seq_clear:N \g_my_items_seq % clear item list
% Opens up a new stream of the file to read into the token list \tl_raw.
\ior_open:Nn \io_stream {cards.csv}
\ior_get:NN \io_stream \tl_raw
\bool_do_until:nn {\ior_if_eof_p:N {\io_stream}} {
\seq_clear:N \g_tmp
\seq_set_split:NnV \g_tmp {,} \tl_raw
\seq_concat:NNN \g_my_items_seq \g_my_items_seq \g_tmp
\ior_get:NN \io_stream \tl_raw
%\seq_show:N \g_my_items_seq
}
\ior_close:N \io_stream
% check whether there are enough items
\int_compare:nNnT {\seq_count:N \g_my_items_seq} < {24} {\msg_error:nn {bingo} {Too~few~items!}}
}
\NewDocumentCommand{\setItems}{}
{
\seq_set_eq:NN \l_my_tmp_items_seq \g_my_items_seq % put in temp seq so that multiple cards can be produced
\prg_replicate:nn {24} %generate random list of 24 items
{
\int_set:Nn \l_tmp_int {\seq_count:N \l_my_tmp_items_seq}% set current length of list
\setrannum {\randomnum} {1} {\int_use:N \l_tmp_int}
\seq_put_right:Nx \g_my_randomized_seq {\seq_item:Nn \l_my_tmp_items_seq {\the\randomnum}}
\seq_remove_all:Nx \l_my_tmp_items_seq {\seq_item:Nn \l_my_tmp_items_seq {\the\randomnum}}
}
\seq_clear:N \l_my_tmp_items_seq %clear temp seq when done
}
\NewDocumentCommand {\NodeText}{}
{
\seq_gpop_right:NN \g_my_randomized_seq \l_tmpa_tl %pop item from randomized seq into token list
\tl_use:N \l_tmpa_tl %use that item.
}
\ExplSyntaxOff
\def\NumOfColumns{5}%
\def\Sequence{1, 2, 3, 4, 5}%
\newcommand{\Size}{3.25cm}
\tikzset{Square/.style={
inner sep=0pt,
text width=\Size,
minimum size=\Size,
draw=black,
align=center,
}
}
\newcommand\BackgroundPic{%
\put(0,0){%
\parbox[b][\paperheight]{\paperwidth}{%
\includegraphics[width=\paperwidth,height=\paperheight,%
keepaspectratio]{wwdc14-home-branding_2x.png}%
\vfill
\centering
\includegraphics[scale=0.3,%
keepaspectratio]{wwdc14-home-branding_2x_footer.png}%
\vspace{0.5cm}
}}}
\begin{document}
\AddToShipoutPicture{\BackgroundPic}
\thispagestyle{empty}
\myItems
\setItems
\begin{figure}[H]
\vspace{6cm}
\centering
\begin{tikzpicture}[draw=black, thick, x=\Size,y=\Size]
\foreach \row in \Sequence{%
\foreach \col in \Sequence {%
\pgfmathtruncatemacro{\value}{\col+\NumOfColumns*(\row-1)}
\pgfmathsetmacro{\ColRowProduce}{\col*\row}
\IfEq{\ColRowProduce}{9}{% If is center square
\node [] at ($(\col,-\row)-(0.5,0.5)$) {\textbf{FREE}};
}{
\node [Square] at ($(\col,-\row)-(0.5,0.5)$) {\large \NodeText};
}
}
}
\end{tikzpicture}
\end{figure}
\end{document}