-
Notifications
You must be signed in to change notification settings - Fork 0
/
board.py
62 lines (55 loc) · 1.74 KB
/
board.py
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
from polygons import *
from random import randrange
def top_row0(x0,y0,canvas):
res = []
for _ in range(5):
gtbh = polygon_gtbh(x0,y0)
res.append((draw_polygon(canvas, gtbh), 'gtbh'))
ltbh = polygon_ltbh(gtbh[2],gtbh[3])
res.append((draw_polygon(canvas, ltbh), 'ltbh'))
x0, y0 = ltbh[2],ltbh[3]
return res
def odd_row1(x0,y0,canvas):
res = []
for _ in range(5):
lt = polygon_lt(x0,y0)
res.append((draw_polygon(canvas, lt), 'lt'))
gt = polygon_gt(lt[2],lt[3])
res.append((draw_polygon(canvas, gt), 'gt'))
x0, y0 = gt[2],gt[3]
return res
def even_row2(x0,y0,canvas):
res = []
for _ in range(5):
gt = polygon_gt(x0,y0)
res.append((draw_polygon(canvas, gt), 'gt'))
lt = polygon_lt(gt[2],gt[3])
res.append((draw_polygon(canvas, lt), 'lt'))
x0,y0 = lt[2],lt[3]
return res
def bottom_row28(x0,y0,canvas):
res = []
for _ in range(5):
gtth = polygon_gtth(x0,y0)
res.append((draw_polygon(canvas, gtth), 'gtth'))
ltth = polygon_ltth(gtth[2], gtth[3])
res.append((draw_polygon(canvas, ltth), 'ltth'))
x0,y0 = ltth[2],ltth[3]
return res
def rc():
return '#%06x' % randrange(0,0xffffff)
def draw_polygon(canvas, coords):
polygon_id = canvas.create_polygon(coords, fill=rc(), dash=(5,2,5,4), outline='#ffffff')
return polygon_id
def draw_board(x0,y0,canvas):
res = []
res.append(top_row0(0,0,canvas))
x0 = 0
y0 = cell_height / 2
for _ in range(13):
res.append(odd_row1(x0,y0,canvas))
res.append(even_row2(x0,y0,canvas))
y0 += cell_height
res.append(odd_row1(x0,y0,canvas))
res.append(bottom_row28(x0,y0,canvas))
return res