-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbingo.pde
455 lines (447 loc) · 11.1 KB
/
bingo.pde
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
/*
Assignment 3, created by Kevin Lu and Aaron Liu
Program name: Number Systems (N.S. Bingo)
Description: A processing program to create PDF of multiple bingo cards for printing in different number systems.
Features:
-5x5 grid for numbers.
-Random number generator.
-Basic interface.
-Button for regenerating numbers.
-Outputs to PDF.
-"FREE" option in the center.
-Buttons to toggle between various number systems.
-Outputs the cards in a visually pleasing manner.
-Can, if requested, generate more than one bingo card as required.
-Can, if requested, generate more than one file's worth of cards.
Required software: Processing 3.1.1 or above.
Website: https://github.com/KevinLu/bingo
*/
/*
Import processing.pdf package and declare variables for each number system.
*/
import processing.pdf.*;
PFont font; //the font for the title of the card
PFont def; //def = default font
PGraphicsPDF pdf;
IntList B = new IntList(); //B, I, N, G, O IntLists for Decimal values.
IntList I = new IntList();
IntList N = new IntList();
IntList G = new IntList();
IntList O = new IntList();
//Binary values
IntList bBin = new IntList();
IntList iBin = new IntList();
IntList nBin = new IntList();
IntList gBin = new IntList();
IntList oBin = new IntList();
//Hexadecimal values
IntList bHex = new IntList();
IntList iHex = new IntList();
IntList nHex = new IntList();
IntList gHex = new IntList();
IntList oHex = new IntList();
//Octal values
IntList bOct = new IntList();
IntList iOct = new IntList();
IntList nOct = new IntList();
IntList gOct = new IntList();
IntList oOct = new IntList();
boolean middle = true;
boolean binaryConverted = false;
boolean hexaConverted = false;
boolean octalConverted = false;
boolean pdfRecord = false;
boolean pdfCollate = false;
int cards = 1;
/*
Setup the main window to be 600 by 600 pixels.
*/
void settings () {
size(600, 600);
}
/*
Create a new window for Settings.
Populate the data structures with random numbers.
*/
void setup () {
//Create Settings window
String[] args = {"Settings"};
SettingsWindow sa = new SettingsWindow();
PApplet.runSketch(args, sa);
surface.setTitle("Number Systems Bingo");
font = createFont("SansSerif.bold", 32);
def = createFont("Tahoma", 32);
//Decimals
for (int x = 0; x != 15; B.append(++x)) {
B.shuffle();
}
for (int x = 15; x != 30; I.append(++x)) {
I.shuffle();
}
for (int x = 30; x != 45; N.append(++x)) {
N.shuffle();
}
for (int x = 45; x != 60; G.append(++x)) {
G.shuffle();
}
for (int x = 60; x != 75; O.append(++x)) {
O.shuffle();
}
//Binary
for (int x = 0; x != 10; bBin.append(++x)) {
bBin.shuffle();
}
for (int x = 10; x != 20; iBin.append(++x)) {
iBin.shuffle();
}
for (int x = 20; x != 30; nBin.append(++x)) {
nBin.shuffle();
}
for (int x = 30; x != 40; gBin.append(++x)) {
gBin.shuffle();
}
for (int x = 40; x != 50; oBin.append(++x)) {
oBin.shuffle();
}
//Hexadecimals
for (int x = 0; x != 50; bHex.append(++x)) {
bHex.shuffle();
}
for (int x = 50; x != 100; iHex.append(++x)) {
iHex.shuffle();
}
for (int x = 100; x != 150; nHex.append(++x)) {
nHex.shuffle();
}
for (int x = 150; x != 200; gHex.append(++x)) {
gHex.shuffle();
}
for (int x = 200; x != 250; oHex.append(++x)) {
oHex.shuffle();
}
//Octals
for (int x = 0; x != 30; bOct.append(++x)) {
bOct.shuffle();
}
for (int x = 30; x != 60; iOct.append(++x)) {
iOct.shuffle();
}
for (int x = 60; x != 90; nOct.append(++x)) {
nOct.shuffle();
}
for (int x = 90; x != 120; gOct.append(++x)) {
gOct.shuffle();
}
for (int x = 120; x != 150; oOct.append(++x)) {
oOct.shuffle();
}
}
/*
Template for a blank bingo card.
*/
void bingoCard() {
int grid_x = 100;
while (grid_x < 580) {
line(grid_x, 100, grid_x, 500);
grid_x += 80;
}
int grid_y = 100;
while (grid_y < 580) {
line(100, grid_y, 500, grid_y);
grid_y += 80;
}
}
/*
(Only to be used by developers to check the X,Y coordinates of the mouse).
*/
void debug() {
fill(0);
textSize(12);
text("X, Y: " + mouseX + " " + mouseY, 40, 12);
}
/*
Free square in the middle. Easy to enable/disable.
*/
void free() {
if (middle) {
fill(255);
rect(260, 260, 80, 80);
fill(0);
textAlign(CENTER);
textSize(25);
text("FREE", 300, 310);
}
}
/*
Randomize function to randomize (regenerate) the numbers.
Since we already populated the lists with the specified values, we can simply shuffle them
to get a random sequence every time.
*/
void regen() {
//shuffle the IntLists
B.shuffle();
I.shuffle();
N.shuffle();
G.shuffle();
O.shuffle();
//shuffle the IntLists
bBin.shuffle();
iBin.shuffle();
nBin.shuffle();
gBin.shuffle();
oBin.shuffle();
//shuffle the IntLists
bOct.shuffle();
iOct.shuffle();
nOct.shuffle();
gOct.shuffle();
oOct.shuffle();
//shuffle the IntLists
bHex.shuffle();
iHex.shuffle();
nHex.shuffle();
gHex.shuffle();
oHex.shuffle();
}
/*
if the octal function is selected, it will display octalConvert().
This is an almost identical copy of the draw() but it changes the decimal to octal.
*/
void octalConvert() {
if (octalConverted) {
background(255);
bingoCard();
textFont(font);
text("Octal Bingo", 300, 25);
textFont(def);
int bingoOffset = 140;
for (int i = 0; i < 5; i++) {
textSize(32);
textAlign(CENTER);
text("B", bingoOffset, 85);
bingoOffset += 80;
text("I", bingoOffset, 85);
bingoOffset += 80;
text("N", bingoOffset, 85);
bingoOffset += 80;
text("G", bingoOffset, 85);
bingoOffset += 80;
text("O", bingoOffset, 85);
bingoOffset += 150;
}
int textY = 150;
textSize(32);
for (int i = 0; i < 5; i++) {
text(Integer.toOctalString(bOct.get(i)), 140, textY);
textY += 80;
}
textY = 150;
for (int j = 0; j < 5; j++) {
text(Integer.toOctalString(iOct.get(j)), 220, textY);
textY += 80;
}
textY = 150;
for (int j = 0; j < 5; j++) {
text(Integer.toOctalString(nOct.get(j)), 300, textY);
textY += 80;
}
textY = 150;
for (int j = 0; j < 5; j++) {
text(Integer.toOctalString(gOct.get(j)), 380, textY);
textY += 80;
}
textY = 150;
for (int j = 0; j < 5; j++) {
text(Integer.toOctalString(oOct.get(j)), 460, textY);
textY += 80;
}
free(); //Add "FREE" tile in the centre.
}
}
/*
if the hexadecimal function is selected, it will display hexaConvert().
This is an almost identical copy of the draw() but it changes the decimal to hexadecimal.
*/
void hexaConvert() {
if (hexaConverted) {
background(255);
bingoCard();
textFont(font);
text("Hexadecimal Bingo", width/2, 25);
textFont(def);
int bingoOffset = 140;
for (int i = 0; i < 5; i++) {
textSize(32);
textAlign(CENTER);
text("B", bingoOffset, 85);
bingoOffset += 80;
text("I", bingoOffset, 85);
bingoOffset += 80;
text("N", bingoOffset, 85);
bingoOffset += 80;
text("G", bingoOffset, 85);
bingoOffset += 80;
text("O", bingoOffset, 85);
bingoOffset += 150;
}
int textY = 150;
textSize(32);
for (int i = 0; i < 5; i++) {
text(hex((byte) bHex.get(i)), 140, textY);
textY += 80;
}
textY = 150;
for (int j = 0; j < 5; j++) {
text(hex((byte) iHex.get(j)), 220, textY);
textY += 80;
}
textY = 150;
for (int j = 0; j < 5; j++) {
text(hex((byte) nHex.get(j)), 300, textY);
textY += 80;
}
textY = 150;
for (int j = 0; j < 5; j++) {
text(hex((byte) gHex.get(j)), 380, textY);
textY += 80;
}
textY = 150;
for (int j = 0; j < 5; j++) {
text(hex((byte) oHex.get(j)), 460, textY);
textY += 80;
}
free(); //Add "FREE" tile in the centre.
}
}
/*
if the binary function is selected, it will display binaryConvert().
This is an almost identical copy of the draw() but it changes the decimal to binary.
*/
void binaryConvert() {
if (binaryConverted) {
background(255);
bingoCard();
textFont(font);
text("Binary Bingo", width/2, 25);
textFont(def);
int bingoOffset = 140;
for (int i = 0; i < 5; i++) {
textSize(32);
textAlign(CENTER);
text("B", bingoOffset, 85);
bingoOffset += 80;
text("I", bingoOffset, 85);
bingoOffset += 80;
text("N", bingoOffset, 85);
bingoOffset += 80;
text("G", bingoOffset, 85);
bingoOffset += 80;
text("O", bingoOffset, 85);
bingoOffset += 150;
}
int textY = 150;
textSize(24);
for (int i = 0; i < 5; i++) {
text(binary(bBin.get(i), 6), 140, textY);
textY += 80;
}
textY = 150;
for (int j = 0; j < 5; j++) {
text(binary(iBin.get(j), 6), 220, textY);
textY += 80;
}
textY = 150;
for (int j = 0; j < 5; j++) {
text(binary(nBin.get(j), 6), 300, textY);
textY += 80;
}
textY = 150;
for (int j = 0; j < 5; j++) {
text(binary(gBin.get(j), 6), 380, textY);
textY += 80;
}
textY = 150;
for (int j = 0; j < 5; j++) {
text(binary(oBin.get(j), 6), 460, textY);
textY += 80;
}
free(); //Add "FREE" tile in the centre.
}
}
/*
The draw function. We initialize all of the functions above in here
and simply use booleans to toggle each one on/off.
*/
void draw () {
background(255);
bingoCard();
//debug();
textSize(32);
textFont(font);
fill(0);
text("Decimal Bingo", width/2, 25);
textFont(def);
int bingoOffset = 140;
for (int i = 0; i < 5; i++) {
textSize(32);
textAlign(CENTER);
text("B", bingoOffset, 85);
bingoOffset += 80;
text("I", bingoOffset, 85);
bingoOffset += 80;
text("N", bingoOffset, 85);
bingoOffset += 80;
text("G", bingoOffset, 85);
bingoOffset += 80;
text("O", bingoOffset, 85);
bingoOffset += 150;
}
int textY = 150;
for (int i = 0; i < 5; i++) {
text(B.get(i), 140, textY);
textY += 80;
}
textY = 150;
for (int j = 0; j < 5; j++) {
text(I.get(j), 220, textY);
textY += 80;
}
textY = 150;
for (int j = 0; j < 5; j++) {
text(N.get(j), 300, textY);
textY += 80;
}
textY = 150;
for (int j = 0; j < 5; j++) {
text(G.get(j), 380, textY);
textY += 80;
}
textY = 150;
for (int j = 0; j < 5; j++) {
text(O.get(j), 460, textY);
textY += 80;
}
octalConvert(); //Add octal conversions.
hexaConvert(); //Add hexadecimal conversions.
binaryConvert(); //Add binary conversions.
free(); //Add "FREE" tile in the centre.
//Add option to output to .PDF
if (pdfRecord) {
save("G:/Documents/BingoCards/" + cards + ".png");
}
/*
Allows to collate multiple .PNG files from pdfRecord
to a single PDF file.
*/
if (pdfCollate) {
pdf = (PGraphicsPDF)beginRecord(PDF, "G:/Documents/BingoCards/cards.pdf");
for (int i = 1; i <= cards; i++) {
PImage recap = loadImage("G:/Documents/BingoCards/" + i + ".png");
image(recap, 0, 0, 600, 600);
if (i != cards) {
pdf.nextPage();
}
}
endRecord();
}
}