Commit f1c0f3f9 authored by hejulian's avatar hejulian

improved output, add clear, change dimensions, fullscreen

parent f564d1a8
import sys
from PyQt5 import QtCore, QtGui, QtWidgets, uic
from PyQt5.QtCore import Qt
# import numpy as np
# import matplotlib.pyplot as plt
# import matplotlib.cm as cm
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
class Canvas(QtWidgets.QLabel):
def __init__(self):
super().__init__()
self.width = 5*128
self.height = 5*128
self.width = 320
self.height = 320
pixmap = QtGui.QPixmap(self.width, self.height)
# pixmap = pixmap.scaled(self.width*5, self.height*5)
self.setPixmap(pixmap)
self.clear_screen()
self.last_x, self.last_y = None, None
self.pen_color = QtGui.QColor('#a42f3b')
......@@ -22,15 +22,23 @@ class Canvas(QtWidgets.QLabel):
print(c)
self.pen_color = QtGui.QColor(c)
def report_pixels(self, x, y):
def clear_screen(self):
empty = np.zeros((self.width, self.height))
self.pixmap().fill(Qt.GlobalColor.transparent)
self.update()
self.report_pixels()
def report_pixels(self):
channels_count = 4
w = int(self.width/5)
h = int(self.height/5)
w = int(self.width)
h = int(self.height)
image = self.pixmap().scaled(w, h).toImage()
s = image.bits().asstring(w * h * channels_count)
# arr = np.frombuffer(s, dtype=np.uint8).reshape((h, w, channels_count))
# img = np.int64(np.all(arr[:, :, :3] == 0, axis=2))
# plt.imsave("image.png", img, cmap=cm.gray)
arr = np.frombuffer(s, dtype=np.uint8).reshape((h, w, channels_count))
img = 1-np.int64(np.all(arr[:, :, :3] == 0, axis=2))
# img = img.reshape()
plt.imsave("image.png", img, cmap=cm.gray)
# img.show()
# print(int(np.clip(x, 0, 600)/600*28), int(np.clip(y, 0, 600)/600*28))
......@@ -42,12 +50,12 @@ class Canvas(QtWidgets.QLabel):
painter = QtGui.QPainter(self.pixmap())
p = painter.pen()
p.setWidth(25)
p.setWidth(5)
p.setColor(self.pen_color)
painter.setPen(p)
painter.drawLine(self.last_x, self.last_y, e.x(), e.y())
self.report_pixels(e.x(), e.y())
self.report_pixels()
painter.end()
self.update()
......@@ -91,12 +99,19 @@ class MainWindow(QtWidgets.QMainWindow):
palette = QtWidgets.QHBoxLayout()
# self.add_palette_buttons(palette)
self.add_buttons(palette)
l.addLayout(palette)
self.setCentralWidget(w)
self.showFullScreen()
def button_pressed(self):
print("Button Pressed")
def button_pressed(self, c):
print("Button Pressed", c)
def add_buttons(self, layout):
btn = QtWidgets.QPushButton("Clear")
btn.clicked.connect(self.canvas.clear_screen)
layout.addWidget(btn)
def add_palette_buttons(self, layout):
for i, c in enumerate(COLORS):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment