-
Notifications
You must be signed in to change notification settings - Fork 0
/
grid.py
133 lines (117 loc) · 3.08 KB
/
grid.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
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
import json
diagram = {"type": "excalidraw", "version": 2,
"source": "https://excalidraw.com", "elements": [],
"appState": {
"gridSize": 20,
"viewBackgroundColor": "#ffffff"
}
}
M = 7
K = 9
N = 10
MR = 2
NR = 3
KC = 4
MC = MR * 2
NC = NR * 2
delimiter_dis = 10
x_base = 720
y_base = 200
grid_size = 20
block_height = 40
block_width = 40
id_base = 0
group_id_base = 0
def create_unique_element_id():
global id_base
id = "element id " + str(id_base)
id_base = id_base + 1
return id
def create_unique_group_id():
global group_id_base
id = "group id " + str(group_id_base)
group_id_base = group_id_base + 1
return id
def create_block_element(x, y, label):
group_id = create_unique_group_id()
rectangle = {
"id": create_unique_element_id(),
"type": "rectangle",
"x": x_base + x,
"y": y_base + y,
"width": 40,
"height": 40,
"angle": 0,
"strokeColor": "#000000",
"backgroundColor": "transparent",
"fillStyle": "hachure",
"strokeWidth": 1,
"strokeStyle": "solid",
"roughness": 1,
"opacity": 100,
"groupIds": [
group_id
],
"strokeSharpness": "sharp",
"seed": 109661683,
"version": 36,
"versionNonce": 1604055805,
"isDeleted": False,
"boundElementIds": None
}
text = {
"id": create_unique_element_id(),
"type": "text",
"x": rectangle["x"] + 13,
"y": rectangle["y"] + 7,
"width": 14,
"height": 25,
"angle": 0,
"strokeColor": "#000000",
"backgroundColor": "transparent",
"fillStyle": "hachure",
"strokeWidth": 1,
"strokeStyle": "solid",
"roughness": 1,
"opacity": 100,
"groupIds": [
group_id
],
"strokeSharpness": "sharp",
"seed": 2123021277,
"version": 3,
"versionNonce": 1854834515,
"isDeleted": False,
"boundElementIds": None,
"text": label,
"fontSize": 20,
"fontFamily": 1,
"textAlign": "center",
"verticalAlign": "middle",
"baseline": 18
}
return rectangle, text
for m in range(M):
for k in range(K):
block = create_block_element(
k * block_width, m * block_height, str(m * K + k))
diagram["elements"].extend(block)
x_base += 500
for k in range(K):
for n in range(N):
block = create_block_element(
n * block_width, k * block_height, str(k * N + n))
diagram["elements"].extend(block)
x_base += 500
for m in range(M):
for n in range(N):
# sum = 0
# for k in range(K):
# sum += (m*K+k) * (k*N+n)
block = create_block_element(
n * block_width, m * block_height, str(m * N + n))
diagram["elements"].extend(block)
with open('grid.excalidraw', 'w+') as diagram_file:
print("xxx")
# print(json.dumps(diagram, indent=2))
json.dump(diagram, diagram_file, indent=2)