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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

Big_Head_   2021-03-28 我要评论
想了解微信跳一跳python自动代码解读1.0的相关内容吗,Big_Head_在本文为您仔细讲解微信跳一跳python自动代码的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:微信跳一跳python自动代码,python微信跳一跳,微信跳一跳,下面大家一起来学习吧。

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

那个跳一跳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()


最终效果:

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们