Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pythondraw
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hejulian
pythondraw
Commits
f564d1a8
Commit
f564d1a8
authored
Oct 14, 2020
by
hejulian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove unneeded packages
parent
c63f1ab6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
12 deletions
+26
-12
image.png
image.png
+0
-0
python_draw.py
python_draw.py
+26
-12
No files found.
image.png
0 → 100644
View file @
f564d1a8
1.69 KB
python_draw.py
View file @
f564d1a8
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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment