diff options
Diffstat (limited to 'turtetris_master/led_output.py')
-rw-r--r-- | turtetris_master/led_output.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/turtetris_master/led_output.py b/turtetris_master/led_output.py index 1b3c435..ecc4d57 100644 --- a/turtetris_master/led_output.py +++ b/turtetris_master/led_output.py @@ -1,5 +1,6 @@ import zmq import json +import copy class Matrix: @@ -35,3 +36,37 @@ class Matrix: for x in range(self.width): for y in range(self.height): self.pixel(x, y, color) + + def set_matrix(self, matrix): + "Set given matrix as matrix" + for x in range(self.width): + for y in range(self.height): + self.pixel(x, y, matrix[y][x]) + + def copy_matrix(self): + "Return copy of current matrix" + return copy.deepcopy(self.__mat__) + + def matrix_diff(self, matrix): + """ + Returns set of changes in matrix + Every item in set is dictionary with following items: + x: X position of led + y: Y position of led + color: string defining color of given led + """ + change = list() + for x in range(self.width): + for y in range(self.height): + if matrix[y][x] != self.__mat__[y][x]: + change.append({ + 'x': x, + 'y': y, + 'color': self.__mat__[y][x] + }) + return change + + def matrix_apply_diff(self, diff): + "Apply diff generated by matrix_diff" + for change in diff: + self.pixel(change['x'], change['y'], change['color']) |