Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
exapunks-hackmatch-bot
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
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
Taddeüs Kroes
exapunks-hackmatch-bot
Commits
1c46685d
Commit
1c46685d
authored
Apr 09, 2020
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Get rid of PIL, do HSV conversion in pure Python instead
parent
efdf4ac5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
6 deletions
+34
-6
interaction.py
interaction.py
+34
-6
No files found.
interaction.py
View file @
1c46685d
...
@@ -5,7 +5,6 @@ sys.path.insert(0, join(dirname(__file__), 'python-xlib'))
...
@@ -5,7 +5,6 @@ sys.path.insert(0, join(dirname(__file__), 'python-xlib'))
import
time
import
time
from
random
import
randint
from
random
import
randint
from
Xlib
import
display
,
X
,
XK
,
ext
from
Xlib
import
display
,
X
,
XK
,
ext
from
PIL
import
Image
WINDOW_WIDTH
=
1600
WINDOW_WIDTH
=
1600
...
@@ -49,11 +48,9 @@ def focus_window(window):
...
@@ -49,11 +48,9 @@ def focus_window(window):
def
screenshot_board
(
window
):
def
screenshot_board
(
window
):
raw
=
window
.
get_image
(
BOARD_X
,
BOARD_Y
,
BOARD_WIDTH
,
BOARD_HEIGHT
,
im
=
window
.
get_image
(
BOARD_X
,
BOARD_Y
,
BOARD_WIDTH
,
BOARD_HEIGHT
,
X
.
ZPixmap
,
0xffffffff
)
X
.
ZPixmap
,
0xffffffff
)
dim
=
BOARD_WIDTH
,
BOARD_HEIGHT
return
BoardImage
(
im
.
data
)
im
=
Image
.
frombytes
(
'RGB'
,
dim
,
raw
.
data
,
'raw'
,
'BGRX'
)
return
im
.
convert
(
'HSV'
)
def
press_keys
(
window
,
keys
):
def
press_keys
(
window
,
keys
):
...
@@ -71,8 +68,39 @@ def press_keys(window, keys):
...
@@ -71,8 +68,39 @@ def press_keys(window, keys):
time
.
sleep
(
KEY_DELAY
/
1000
)
time
.
sleep
(
KEY_DELAY
/
1000
)
def
rgb2hsv
(
r
,
g
,
b
):
r
/=
255
g
/=
255
b
/=
255
cmax
=
max
(
r
,
g
,
b
)
cmin
=
min
(
r
,
g
,
b
)
diff
=
cmax
-
cmin
if
cmax
==
cmin
:
h
=
0
elif
cmax
==
r
:
h
=
(
60
*
((
g
-
b
)
/
diff
)
+
360
)
%
360
elif
cmax
==
g
:
h
=
(
60
*
((
b
-
r
)
/
diff
)
+
120
)
%
360
elif
cmax
==
b
:
h
=
(
60
*
((
r
-
g
)
/
diff
)
+
240
)
%
360
h
=
int
(
h
*
256
/
360
)
s
=
0
if
cmax
==
0
else
int
(
diff
*
256
/
cmax
)
v
=
int
(
cmax
*
256
)
return
h
,
s
,
v
class
BoardImage
:
def
__init__
(
self
,
data
):
self
.
data
=
data
def
getpixel
(
self
,
xy
):
x
,
y
=
xy
i
=
(
y
*
BOARD_WIDTH
+
x
)
*
4
b
,
g
,
r
=
self
.
data
[
i
:
i
+
3
]
return
rgb2hsv
(
r
,
g
,
b
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
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