changeset 58:10476f40ec9d

Tile: add unparse_tile method The opposite of parse_tile, of course.
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Sun, 08 Sep 2019 21:09:17 -0400
parents 028fd04fcad5
children a53572bf5a26
files tilerswift
diffstat 1 files changed, 7 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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):