comparison scripts/partition_helper @ 401:20b424c5c1ef

generated some templates
author Adrianna Pińska <adrianna.pinska@gmail.com>
date Sat, 17 Sep 2011 11:45:24 +0200
parents 46565a047ac0
children fca61cd8fc33
comparison
equal deleted inserted replaced
400:03db0d517ac3 401:20b424c5c1ef
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 HEIGHT_PARTITIONS = (
4 (2,2),
5 (2,3),
6 (2,5),
7 (2,6),
8 )
9
10 WIDTH_PARTITIONS = (
11 (1,3),
12 (2,2),
13 (2,4),
14 (2,5),
15 )
16
17 SAVE_LOCATION = "data/levels/templates"
3 18
4 def partition(total, parts, sepwidth=1): 19 def partition(total, parts, sepwidth=1):
5 seps = parts - 1 20 seps = parts - 1
6 space = total - 2 - sepwidth * seps 21 space = total - 2 - sepwidth * seps
7 return float(space) / parts 22 return float(space) / parts
13 size = partition(num, i, sepwidth) 28 size = partition(num, i, sepwidth)
14 if size > 0 and int(size) == size: 29 if size > 0 and int(size) == size:
15 partitions.append((i, size)) 30 partitions.append((i, size))
16 return partitions 31 return partitions
17 32
18 33 def print_all():
19 if __name__ == "__main__":
20 height = ["FLOOR HEIGHT: PARTS x PART HEIGHT"] 34 height = ["FLOOR HEIGHT: PARTS x PART HEIGHT"]
21 for sepwidth in range(1, 28): 35 for sepwidth in range(1, 28):
22 partitions = find_partitions(30, sepwidth) 36 partitions = find_partitions(30, sepwidth)
23 if partitions: 37 if partitions:
24 height.append("%s: %s" % (sepwidth, 38 height.append("%s: %s" % (sepwidth,
33 47
34 height.extend([""] * 6) 48 height.extend([""] * 6)
35 height = [l.ljust(50) for l in height] 49 height = [l.ljust(50) for l in height]
36 pairs = zip(height, width) 50 pairs = zip(height, width)
37 print "\n".join(["%s %s" % p for p in pairs]) 51 print "\n".join(["%s %s" % p for p in pairs])
52
53 def make_partition(height, width):
54 sepheight, hparts = height
55 pheight = int(partition(30, hparts, sepheight))
56 sepwidth, wparts = width
57 pwidth = int(partition(40, wparts, sepwidth))
58
59 wsep = 'X' * sepwidth
60 partrow = 'X' + wsep.join(['.' * pwidth for i in range(wparts)]) + 'X'
61 partblock = '\n'.join([partrow for i in range(pheight)]) + '\n'
62 seprow = 'X' * 40
63 sepblock = '\n'.join([seprow for i in range(sepheight)]) + '\n'
64 level = '%s\n%s%s' % (seprow, sepblock.join([partblock for i in range(hparts)]), seprow)
65 level = level[:162] + 'E' + level[163:1190] + 'e' + level[1191:]
66 dims = '%dx%d'% (wparts, hparts)
67 f = open('%s/%s.txt' % (SAVE_LOCATION, dims), 'w')
68 f.write('%s template\n' % dims)
69 f.write('lab\n')
70 f.write('test.ogg\n')
71 f.write(level + '\n')
72 f.write('end\n')
73 f.close()
74
75 def generate_partitions():
76 for height in HEIGHT_PARTITIONS:
77 for width in WIDTH_PARTITIONS:
78 make_partition(height, width)
79
80 if __name__ == "__main__":
81 generate_partitions()