python跳一跳辅助学习

微信跳一跳辅助工具

准备工具

  • adb驱动
  • 安卓手机
  • 打开手机的调试模式
  • usb接好手机和电脑

 

PyCharm:全宇宙唯一一款专门用于Python开发IDE工具

 

实现原理:

  • 获取手机的实时的截图
  • 点击起始位置和落地位置
  • 计算两个点的距离
  • 计算按压时间
  • 发送按压指令
  • 重新刷新手机截图
实现代码:
import os
import PIL,numpy
import  matplotlib.pylab as plt
from matplotlib.animation import FuncAnimation
import time
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 340 490 340 490 {}'.format(int(distance*1)))
    #手机的单击位置,0 0 0 0 0 ,x轴y轴滑动后的xy轴单击时间


def on_calck(event, coor=[]):#绑定鼠标的单击事件[(x,y)(x2,y2)],
    global need_update
    coor.append((event.xdata, event.ydata))
    if len(coor) == 2:
        jump_to_next(coor.pop(), coor.pop())
    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,

figure = plt.figure() #创建一个空白的图片对象、创建一张图片
axes_image = plt.imshow(get_screen_image(), animated=True)#把获取的图片画在坐标轴上
figure.canvas.mpl_connect('button_press_event', on_calck)
ani = FuncAnimation(figure, update_screen, interval=50, blit=True)
plt.show()

 

 
详情:
https://github.com/wangshub/wechat_jump_game
posted @ 2018-01-06 20:37  safran  阅读(1775)  评论(0编辑  收藏  举报