跳一跳python辅助程序

import os
import PIL,numpy
import matplotlib.pyplot as plt
import time
from matplotlib.animation import FuncAnimation
need_update=True

def get_screen_image():
    os.system('adb shell screencap -p /sdcard/screen.png')#获取手机当前截面截图
    os.system('adb pull /sdcard/screen.png') #下载当前截图到当前文件夹
    return numpy.array(PIL.Image.open('screen.png')) #返回图片像素数组

def jump_to_next(point1,point2):
    x1,y1=point1
    x2,y2=point2
    distance=((x2-x1)**2+(y2-y1)**2)**0.5
    #os.system('adb shell input swipe 320 410 320 410{}'.format(int(distance*1.35)))  #按压操作时间
    os.system('adb shell input swipe 320 410 320 410 {}'.format(
        int(distance * 1.35)))




def on_clock(event,coor=[]):
    coor.append((event.xdata,event.ydata))
    if(len(coor)==2):
        jump_to_next(coor.pop(),coor.pop())
    global need_update
    need_update = True

def update_screen(frame):  #跟新图片
    global need_update
    if(need_update):
        time.sleep(1)
        axes_image.set_array(get_screen_image())
        need_update=False
    return axes_image,





get_screen_image()
figure =plt.figure()
axes_image =plt.imshow(get_screen_image(),animated=True)  #把获取的图片画在坐标轴上
figure.canvas.mpl_connect('button_press_event',on_clock)
ani=FuncAnimation(figure,update_screen,interval=50,blit=True)
plt.show()

没有更多推荐了,返回首页