Mercurial > mamba
comparison scripts/partition_helper @ 354:46565a047ac0
silly partition helper for level design
author | Adrianna Pińska <adrianna.pinska@gmail.com> |
---|---|
date | Fri, 16 Sep 2011 23:38:53 +0200 |
parents | |
children | 20b424c5c1ef |
comparison
equal
deleted
inserted
replaced
353:62a2a659c69b | 354:46565a047ac0 |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 | |
4 def partition(total, parts, sepwidth=1): | |
5 seps = parts - 1 | |
6 space = total - 2 - sepwidth * seps | |
7 return float(space) / parts | |
8 | |
9 | |
10 def find_partitions(num, sepwidth): | |
11 partitions = [] | |
12 for i in range(2, num): | |
13 size = partition(num, i, sepwidth) | |
14 if size > 0 and int(size) == size: | |
15 partitions.append((i, size)) | |
16 return partitions | |
17 | |
18 | |
19 if __name__ == "__main__": | |
20 height = ["FLOOR HEIGHT: PARTS x PART HEIGHT"] | |
21 for sepwidth in range(1, 28): | |
22 partitions = find_partitions(30, sepwidth) | |
23 if partitions: | |
24 height.append("%s: %s" % (sepwidth, | |
25 " ".join([" %dx%d" % (i, size) for (i, size) in partitions]))) | |
26 | |
27 width = ["COLUMN WIDTH: PARTS x PART WIDTH"] | |
28 for sepwidth in range(1, 38): | |
29 partitions = find_partitions(40, sepwidth) | |
30 if partitions: | |
31 width.append("%s: %s" % (sepwidth, | |
32 " ".join([" %dx%d" % (i, size) for (i, size) in partitions]))) | |
33 | |
34 height.extend([""] * 6) | |
35 height = [l.ljust(50) for l in height] | |
36 pairs = zip(height, width) | |
37 print "\n".join(["%s %s" % p for p in pairs]) |