-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbingo.py
More file actions
91 lines (75 loc) · 2.48 KB
/
Copy pathbingo.py
File metadata and controls
91 lines (75 loc) · 2.48 KB
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
import math
import random
terms = ['Cidadão',
'Direito Político',
'Direito social',
'Direito civil',
'Direitos individuais',
'Direito coletivo',
'Constituição',
'Constituição cidadã',
'Estatuto da Criança e Adolescente'
]
h = 842/2
w = 595
size('A4')
columns = math.ceil(math.sqrt(len(terms)))
# for the middle cell to be a “free space” there needs to be at least one word
# less than cells! (and this only works when there are an odd number of columns)
free_spaces = columns * columns - len(terms)
free_space_term = 'Espaço Livre'
margin = 30
if w < h:
small = w
else:
small = h
s_w = s_h = (small - margin * 2) / columns
margin_x = (w - s_w * columns) / 2
margin_y = (h - s_h * columns) / 2
n_cards = 16
cell_margin = s_w * 0.05
for card in range(n_cards):
if card % 2 == 0:
offset_y = height() / 2
else:
offset_y = 0
aux_terms = terms.copy()
random.shuffle(aux_terms)
if columns % 2 != 0 and free_spaces > 0:
i_term = round(columns * columns / 2)
aux_terms.insert(i_term, free_space_term)
for c in range(columns):
for l in range(columns):
x = s_w * c + margin_x
y = s_h * l + margin_y + offset_y
fill(None)
stroke(0)
rect(x, y, s_w, s_h)
i = c * columns + l
if i < len(terms):
current_term = aux_terms[i]
else:
current_term = "Termo faltante"
can_print = False
fs = 16
tx = x + cell_margin
ty = y + cell_margin
tw = s_w - cell_margin * 2
th = s_h - cell_margin * 2
while can_print == False and fs > 0:
font('Helvetica', fs)
overflow = textOverflow(current_term,(tx, ty, tw, th),align="center")
if overflow == "":
can_print = True
else:
fs = fs - 1
stroke(None)
if current_term == free_space_term:
fill(0.5, 0.5, 0.5)
else:
fill(0)
text_width, text_height = textSize(current_term, align="center", width=tw)
cell_offset_y = (th - text_height) / 2
textBox(current_term, (tx, ty - cell_offset_y, tw, th), align="center")
if card > 0 and card % 2 != 0 and card < n_cards-1:
newPage()