当前位置: 移动技术网 > IT编程>脚本编程>Python > 微信跳一跳python自动代码解读1.0

微信跳一跳python自动代码解读1.0

2018年01月28日  | 移动技术网IT编程  | 我要评论

左藤麻衣,清醒视觉,世界拳王争霸赛直播

微信跳一跳自动代码,具体内容如下

那个跳一跳python“外挂”,有几个python文件,其中有一个是得到截图,然后鼠标在图片上点击两次,python窗口上会打印两次鼠标的位置,并且会跟上一行这两个点之间的距离。

样例

这个功能我先给除去获取截屏,就说怎么在某张图片上算出两次点击的距离。

首先,需要用到图形模块,PIL:

from PIL import Image
img = Image.open('0.jpg')

然后用图形绘制模块matplotlib来给出一个plot对象:

import matplotlib.pyplot as plt
fig = plt.figure()

给这个对象加上刚刚打开图片的标签:

plt.imshow(img, animated = True)

然后用matplotlib的canvas.mpl_connect函数,将我们点击的动作和图片连接起来,这个函数的第二个参数要我们自己的写。

fig.canvas.mpl_connect('button_press_event', on_press)

在这个自定义的on_press函数,我们要实现得到两个点以后再算出距离。
那么我们就要有变量来储存两个点,临时储存点,来计算点击了多少次,横纵坐标
分别用全局变量cor=[0,0],coords=[], click_count=0,ix,iy

global ix,iy
 global click_count
 global cor

 ix,iy = event.xdata, event.ydata
 coords = []
 coords.append((ix,iy))
 print("now = ", coords)
 cor.append(coords)
 click_count += 1

先把点储存在临时的coords里面,打印出当前位置,然后将临时的放入全局变量cor里面, 并且点击次数+1.

 if click_count > 1:
  click_count = 0

  cor1 = cor.pop()
  cor2 = cor.pop()

  distance = (cor1[0][0] - cor2[0][0]) **2 + (cor1[0][1] - cor2[0][1]) **2
  distance = distance ** 0.5
  print("distance = ", distance)


当点击次数大于1的时候,就说明已经储存了两个点了。
这里用的栈pop()方法得到两个点,分别放入cor1 和 cor2, 那么cor1 和 cor2 就是两个点了。
接着计算出距离distance就行了。

完整代码:

import numpy as np
from matplotlib.animation import FuncAnimation
import matplotlib.pyplot as plt
from PIL import Image
def on_press(event):
 global ix,iy
 global click_count
 global cor

 ix,iy = event.xdata, event.ydata
 coords = []
 coords.append((ix,iy))
 print("now = ", coords)
 cor.append(coords)

 click_count += 1
 if click_count > 1:
  click_count = 0

  cor1 = cor.pop()
  cor2 = cor.pop()

  distance = (cor1[0][0] - cor2[0][0]) **2 + (cor1[0][1] - cor2[0][1]) **2
  distance = distance ** 0.5
  print("distance = ", distance)

cor = [0,0]
click_count = 0
fig = plt.figure()
img = Image.open('0.jpg')
#updata = True

plt.imshow(img, animated= True)

fig.canvas.mpl_connect('button_press_event', on_press)
plt.show()


最终效果:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网