-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboogiewonderland.py
75 lines (55 loc) · 1.69 KB
/
boogiewonderland.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
import main
import copy
import random
import os
import json
def LetsDanceTonight():
"""Shuffle les batiments. Boogie Wonderland !"""
C = main.C
typeset = [0, 2, 3, 4, 5, 6, 7, 8]
newbatlist = []
for b in C.mb.batlist:
newb = copy.deepcopy(b)
if newb.type != 1 and newb.type != 9:
newb.type = random.choice(typeset)
newbatlist.append(newb.__dict__)
path = os.path.join(os.getcwd(), "data", "mapshuffled")
try:
os.makedirs(path)
except FileExistsError:
pass
if os.name == "nt":
with open(os.path.join(f"{path}\\map.json"), 'w') as file:
file.write(json.dumps(newbatlist, sort_keys=True, indent=4 ))
else:
with open(os.path.join(f"{path}/map.json"), 'w') as file:
file.write(json.dumps(self._dumpsBatList(), sort_keys=True, indent=4 ))
from PIL import Image
from numpy import asarray, vectorize
def VoulezVous():
"""Sort la map d'une image"""
ctotype = {
(88, 209, 43, 255): 1,
(91, 206, 47, 255):1,
(205, 92, 17, 255) : 0,
(235, 64, 7, 255): 0,
(226, 112, 121, 255): 2,
(61, 7, 235, 255): 3,
(7, 235, 235, 255): 4,
(168, 7, 235, 255): 5,
(0, 0, 0, 255): 6,
(8, 19, 1, 255) : 6,
(255, 255, 255, 255): 7,
(179, 94, 173, 255) : 8
}
img = Image.open("VilleType-Centrique.png")
data = asarray(img)
map = []
for l in data:
ll = []
for e in l:
ll.append(ctotype[tuple(e)])
map.append(ll)
print(map)
if __name__ == "__main__":
VoulezVous()