aboutsummaryrefslogtreecommitdiff
path: root/turtetris_master/led_output.py
diff options
context:
space:
mode:
authorKarel Kočí <karel.koci@nic.cz>2018-01-30 16:36:54 +0100
committerKarel Kočí <karel.koci@nic.cz>2018-01-30 16:36:54 +0100
commite027b3020140fa4d9a599521d2ab49d0578b85bd (patch)
tree3e4b080abf5e95baa3e2617213ddd563d2ec470a /turtetris_master/led_output.py
parent1dae42389b97b27e6c11d5bb093270e07e6fe05e (diff)
downloadturris-tetris-e027b3020140fa4d9a599521d2ab49d0578b85bd.tar.gz
turris-tetris-e027b3020140fa4d9a599521d2ab49d0578b85bd.tar.bz2
turris-tetris-e027b3020140fa4d9a599521d2ab49d0578b85bd.zip
Add replay mode
Diffstat (limited to 'turtetris_master/led_output.py')
-rw-r--r--turtetris_master/led_output.py35
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'])