Commit f564d1a8 authored by hejulian's avatar hejulian

remove unneeded packages

parent c63f1ab6
image.png

1.69 KB

import sys
from PyQt5 import QtCore, QtGui, QtWidgets, uic
from PyQt5.QtCore import Qt
import numpy as np
# import numpy as np
# import matplotlib.pyplot as plt
# import matplotlib.cm as cm
class Canvas(QtWidgets.QLabel):
def __init__(self):
super().__init__()
pixmap = QtGui.QPixmap(28, 28)
self.width = 5*128
self.height = 5*128
pixmap = QtGui.QPixmap(self.width, self.height)
# pixmap = pixmap.scaled(self.width*5, self.height*5)
self.setPixmap(pixmap)
self.last_x, self.last_y = None, None
self.pen_color = QtGui.QColor('#000000')
self.pen_color = QtGui.QColor('#a42f3b')
def set_pen_color(self, c):
print(c)
self.pen_color = QtGui.QColor(c)
def report_pixels(self, x, y):
print(int(np.clip(x, 0, 600)/600*28), int(np.clip(y, 0, 600)/600*28))
channels_count = 4
w = int(self.width/5)
h = int(self.height/5)
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)
# img.show()
# print(int(np.clip(x, 0, 600)/600*28), int(np.clip(y, 0, 600)/600*28))
def mouseMoveEvent(self, e):
if self.last_x is None: # First event.
......@@ -29,10 +42,11 @@ class Canvas(QtWidgets.QLabel):
painter = QtGui.QPainter(self.pixmap())
p = painter.pen()
p.setWidth(600/28)
p.setWidth(25)
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())
painter.end()
......@@ -46,12 +60,12 @@ class Canvas(QtWidgets.QLabel):
self.last_x = None
self.last_y = None
COLORS = [
# COLORS = ['#a42f3b'
# 17 undertones https://lospec.com/palette-list/17undertones
'#000000', '#141923', '#414168', '#3a7fa7', '#35e3e3', '#8fd970', '#5ebb49',
'#458352', '#dcd37b', '#fffee5', '#ffd035', '#cc9245', '#a15c3e', '#a42f3b',
'#f45b7a', '#c24998', '#81588d', '#bcb0c2', '#ffffff',
]
# '#000000', '#141923', '#414168', '#3a7fa7', '#35e3e3', '#8fd970', '#5ebb49',
# '#458352', '#dcd37b', '#fffee5', '#ffd035', '#cc9245', '#a15c3e', '#a42f3b',
# '#f45b7a', '#c24998', '#81588d', '#bcb0c2', '#ffffff',
# ]
class QPaletteButton(QtWidgets.QPushButton):
......@@ -76,7 +90,7 @@ class MainWindow(QtWidgets.QMainWindow):
l.addWidget(self.canvas)
palette = QtWidgets.QHBoxLayout()
self.add_palette_buttons(palette)
# self.add_palette_buttons(palette)
l.addLayout(palette)
self.setCentralWidget(w)
......
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