"""Turn a tools/mosaic.py .cells file (row col code colour per line) into the title_run lines of a path mod: runs of the same tile and colour along a row. Usage: python3 tools/cells_to_runs.py LOGO.cells""" import sys cells = sorted(tuple(map(int, l.split())) for l in open(sys.argv[1]) if l.strip()) runs = [] for row, col, code, colour in cells: if runs and runs[-1][0] == row and runs[-1][1] + runs[-1][2] == col and runs[-1][3:] == [code, colour]: runs[-1][2] += 1 else: runs.append([row, col, 1, code, colour]) for r in runs: print("title_run " + " ".join(map(str, r))) print(f"; {len(runs)} runs, {5 * len(runs) + 2} bytes of logo data", file=sys.stderr)