|
|
@ -1,8 +1,8 @@ |
|
|
|
import sys |
|
|
|
import sys |
|
|
|
|
|
|
|
|
|
|
|
import numpy as np |
|
|
|
import numpy as np |
|
|
|
from PyQt5.QtCore import QTimer, QSize |
|
|
|
from PyQt5.QtCore import QTimer |
|
|
|
from PyQt5.QtGui import QPaintEvent, QPixmap, QImage, QPainter, QColor |
|
|
|
from PyQt5.QtGui import QPixmap, QImage |
|
|
|
from PyQt5.QtWidgets import QApplication, QWidget, QLabel |
|
|
|
from PyQt5.QtWidgets import QApplication, QWidget, QLabel |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -49,7 +49,7 @@ class AnimatorWindow(QWidget): |
|
|
|
super().__init__() |
|
|
|
super().__init__() |
|
|
|
self.timer = QTimer(self) |
|
|
|
self.timer = QTimer(self) |
|
|
|
self.timer.timeout.connect(self.step) |
|
|
|
self.timer.timeout.connect(self.step) |
|
|
|
self.timer.setInterval(16) |
|
|
|
self.timer.setInterval(17) |
|
|
|
self.timer.start() |
|
|
|
self.timer.start() |
|
|
|
|
|
|
|
|
|
|
|
self.grid = readGrid("input") |
|
|
|
self.grid = readGrid("input") |
|
|
@ -59,16 +59,19 @@ class AnimatorWindow(QWidget): |
|
|
|
self.resize(self.w, self.h) |
|
|
|
self.resize(self.w, self.h) |
|
|
|
self.label = QLabel(self) |
|
|
|
self.label = QLabel(self) |
|
|
|
self.label.resize(self.w, self.h) |
|
|
|
self.label.resize(self.w, self.h) |
|
|
|
|
|
|
|
self.image = self.getImage() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def paintEvent(self, ev): |
|
|
|
|
|
|
|
self.label.setPixmap(QPixmap.fromImage(self.image)) |
|
|
|
|
|
|
|
self.update() |
|
|
|
|
|
|
|
|
|
|
|
def getImage(self): |
|
|
|
def getImage(self): |
|
|
|
h, w = self.grid.shape |
|
|
|
h, w = self.grid.shape |
|
|
|
colorArray = np.zeros((w, h, 3), dtype=np.uint8) |
|
|
|
colorArray = np.zeros((h, w, 3), dtype=np.uint8) |
|
|
|
|
|
|
|
|
|
|
|
# something is still wrong here ): |
|
|
|
colorArray[:, :] = [40, 40, 90] |
|
|
|
a = np.argwhere(self.grid == ">").T |
|
|
|
colorArray[self.grid == ">"] = [40, 255, 40] |
|
|
|
b = np.argwhere(self.grid == "v").T |
|
|
|
colorArray[self.grid == "v"] = [255, 40, 40] |
|
|
|
colorArray[a[1], a[0]] = [255, 0, 0] |
|
|
|
|
|
|
|
colorArray[b[1], b[0]] = [0, 255, 0] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
image = QImage(colorArray.data, w, h, 3 * w, QImage.Format_RGB888) |
|
|
|
image = QImage(colorArray.data, w, h, 3 * w, QImage.Format_RGB888) |
|
|
|
return image.scaled(self.w, self.h) |
|
|
|
return image.scaled(self.w, self.h) |
|
|
@ -76,8 +79,7 @@ class AnimatorWindow(QWidget): |
|
|
|
def step(self): |
|
|
|
def step(self): |
|
|
|
step(">", self.grid) |
|
|
|
step(">", self.grid) |
|
|
|
step("v", self.grid) |
|
|
|
step("v", self.grid) |
|
|
|
|
|
|
|
self.image = self.getImage() |
|
|
|
self.label.setPixmap(QPixmap.fromImage(self.getImage())) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
if __name__ == "__main__": |
|
|
|