Python编程入门指南下册,第20章,20.3.3选择起点与终点实现跳跃,353页,跳一次后程序就自动退出,不能继续跳
发表在Python视频课程答疑 2019-10-12
是否精华
版块置顶:
import PIL,numpy
import matplotlib.pyplot as plt
from matplotlib.widgets import Button
import warnings
warnings.filterwarnings('ignore')
import os
import time
import threading
coor=[]
ax=None
isAuto=False

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 on_click(event):
    if isAuto==False:
        if event.xdata!=None and event.ydata!=None:
            x=float(event.xdata)
            y=float(event.ydata)
            if x>70 and y>70:
                coor.append((x,y))
                if len(coor)==1:
                    print('选中起点')
                else:
                    print('选中终点')
                global ax
                ax=figure.add_subplot(1,1,1)
                ax.plot(x,y,'r*')
                figure.canvas.draw()
                if len(coor)==2:
                    jump_to_next(coor.pop(),coor.pop())
                    ax.lines.clear()
                    th=threading.Thread(target=update)
                    th.start()
    else:
        print('已开启自动模式!')

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 550 1550 550 1550 {}'.format(int(distance*1.35)))
    print('跳')

def update():
    time.sleep(0.8)
    print('更新')
    axes_image.set_array(get_screen_image())
    print(1)
    figure.canvas.draw()
    print(123)

if __name__=='__main__':
    figure=plt.figure()
    axes_image=plt.imshow(get_screen_image(),animated=True)
    figure.canvas.mpl_connect('button_press_event',on_click)
    reelect_button_position=plt.axes([0.79,0.8,0.1,0.08])
    m=numpy.array(PIL.Image.open('image/bt.png'))
    reelect_button=Button(reelect_button_position,label='',image=m)
    m1=numpy.array(PIL.Image.open('image/bt1.png'))
    auto_button_position=plt.axes([0.79,0.65,0.1,0.08])
    auto_button=Button(auto_button_position,label='',image=m1)
    plt.show()
    reelect_button=Button(reelect_button_position==m)
    m1=numpy.array(PIL.Image.open())
    auto_button_position=plt.axes([])
    auto_button=Button(auto_button_position==m1)
    plt.show()


2019-10-12 10:55:33编辑
分享到:
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照