Add tunnel generator.
[tabakrolletjie.git] / misc / tunnels.py
1 """ Generate some tunnels and print them. """
2
3 import json
4 import sys
5
6 replace = None
7 if len(sys.argv) == 2:
8     replace = sys.argv[1]
9
10 obstacle_defaults = {
11     "type": "wall",
12     "vertices": [],
13 }
14
15 w, h = 1024, 704
16 cx, cy = int(w / 2), int(h / 2)
17 gap_width = 88
18 wall_width = 64
19 block_width = gap_width + wall_width
20
21
22 def make_wall(i, j):
23     wall = obstacle_defaults.copy()
24     top = cx - (gap_width / 2) + (i * block_width)
25     bottom = top - wall_width
26     left = cy + (gap_width / 2) + (j * block_width)
27     right = left + wall_width
28     wall["vertices"] = [
29         [left, top], [right, top], [right, bottom], [left, bottom],
30     ]
31     return wall
32
33 walls = []
34
35 for i in (-2, -1, 0, 1):
36     for j in (-2, -1, 0, 1, 2, 3):
37         walls.append(make_wall(i, j))
38
39 if replace:
40     with open(replace, "r") as f:
41         station = json.load(f)
42     station["obstacles"] = walls
43     with open(replace, "w") as f:
44         json.dump(station, f, indent=2)
45 else:
46     print json.dumps(walls, indent=2)