PyThon--写跳一跳外挂

#!/user/bin/env python
# _*_ coding:utf-8 _*_
import os
import PIL
import numpy
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation# 刷新用的
import time
need_updata=True
 
 
#获取手机截图
def get_screen_img():
    #获取哦当前界面手机截屏
    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):
    #取出两次点击位置的x,y坐标
    x1,y1=point1;
    x2,y2=point2;
    #通过勾股定理计算两次点击之间的距离
    distance=((x2-x1)**2+(y2-y1)**2)**0.5
    #点击     #四个数字    按下  抬起的x,y坐标   {}为占位符         #1.35  一个像素点按压1.35毫秒
    os.system('adb shell input swipe 320 410 320 410 {}'.format(int(distance*1.35)));
 
 
 
 
#event   默认传过来的    点击事件的坐标位置
def on_click(event,coor=[]):#[(1,2),(1,2)]  ;列表里面加元祖
    global need_updata  # 使用全局变量   need_updata
 
    #添加点击坐标
    coor.append((event.xdata,event.ydata))
    if len(coor)==2:
        #list集合中的.pop()方法 ,  给别人的同时删除最后一个元素
        jump_to_next(coor.pop(),coor.pop())
    need_updata = True#点击两次之后变为True
# 更新图片(重画图片)
def update_screen(frame):
    global need_updata  # 使用全局变量   need_updata
    if need_updata:
        time.sleep(1)#睡一秒钟在画图
        axes_image.set_array(get_screen_img());  # 重画图片   get_screen_img()函数加括号   才执行
        need_updata=False
    return axes_image,
 
 
 
 
 
 
 
 
 
#创建空白的图片
figure=plt.figure()
#吧获取的图片显示到坐标上
axes_image=plt.imshow(get_screen_img(),animated=True)
 
 
 
#调用函数    后面写括号:执行完函数,将返回值传过来
#参数2   函数对象    做单击事件的
figure.canvas.mpl_connect('button_press_event',on_click)
#参数一   刷新的对象,所以没括号
#参数二    图片  接收元祖   所以加逗号   update_screen函数的返回值
#参数三    50毫秒
ani=FuncAnimation(figure,update_screen,interval=50,blit=True)#函数会一直循环
plt.show();

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

飞飞翼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值