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编辑

购物车
发表新帖
立即签到







