# HG changeset patch # User Jordi GutiƩrrez Hermoso # Date 1567991357 14400 # Node ID 10476f40ec9d48b1690493146256dd21de8b2cb1 # Parent 028fd04fcad5a4d69fa7a7a6df6ec81b8492d64a Tile: add unparse_tile method The opposite of parse_tile, of course. diff --git a/tilerswift b/tilerswift --- a/tilerswift +++ b/tilerswift @@ -79,6 +79,13 @@ rows.append(row) return rows + @classmethod + def unparse_tile(cls, rows): + """Given an 8x8 array of integers, convert it to a raw tile's bytes.""" + lowplane = bytes([int(''.join(str(num & 1) for num in row), 2) for row in rows]) + hiplane = bytes([int(''.join(str((num & 2) >> 1) for num in row), 2) for row in rows]) + return lowplane + hiplane + class GridHolder(object): def __init__(self, things, numrows, numcols, fillvalue=None):