import sys import math STATION_ICON_SIZE = 90 PILE_ICON_SIZE = 40 PILE_X_OFFSET = 200 ROW_RATE = 3 COL_RATE = 10 def matrix(n): v = (n / (ROW_RATE * COL_RATE)) ** 0.5 r = int(round(ROW_RATE * v)) c = math.ceil(n / r) return r, c def station_pos(r): A = (STATION_ICON_SIZE + PILE_ICON_SIZE) // 2 B = (STATION_ICON_SIZE - PILE_ICON_SIZE) // 2 return (0, (r - 1) * A - B) def pile_pos(c, n): A = STATION_ICON_SIZE + PILE_ICON_SIZE lst = [] for i in range(n): x = (i % c) * A + PILE_X_OFFSET y = (i // c) * A lst.append((x, y)) return lst def link(c, n): lst = [] for i in range(n): if i % c != 0: lst.append(i - 1, i) else: lst.append(-1, i) return lst def pile_layout(n): r, c = matrix(n) print(r, c) print(station_pos(r)) print(pile_pos(c, n)) print(link(c, n)) def main(): if len(sys.argv) < 2: print("test.py ") return pile_layout(int(sys.argv[1])) if __name__ == '__main__': main()