-
Notifications
You must be signed in to change notification settings - Fork 19
/
stick-hero.py
59 lines (41 loc) · 1.3 KB
/
stick-hero.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3
from ppadb.client import Client
from PIL import Image
import numpy
import time
adb = Client(host='127.0.0.1', port=5037)
devices = adb.devices()
if len(devices) == 0:
print('no device attached')
quit()
device = devices[0]
while True:
image = device.screencap()
with open('screen.png', 'wb') as f:
f.write(image)
image = Image.open('screen.png')
image = numpy.array(image, dtype=numpy.uint8)
pixels = [list(i[:3]) for i in image[1700]]
transitions = []
ignore = True
black = True
for i, pixel in enumerate(pixels):
r, g, b = [int(i) for i in pixel]
if ignore and (r+g+b) != 0:
continue
ignore = False
if black and (r+g+b) != 0:
black = not black
transitions.append(i)
continue
if not black and (r+g+b) == 0:
black = not black
transitions.append(i)
continue
start, target1, target2 = transitions
gap = target1 - start
target = target2 - target1
distance = (gap + target / 2) * .98
print(f'transition points: {transitions}, distance: {distance}')
device.shell(f'input touchscreen swipe 500 500 500 500 {int(distance)}')
time.sleep(2.5)