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

作者:Big_Head_ 时间:2022-11-30 05:31:49 

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

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

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

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

首先,需要用到图形模块,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()

最终效果:

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

来源:http://blog.csdn.net/Big_Head_/article/details/78976302

标签:python,微信,跳一跳
0
投稿

猜你喜欢

  • PHP header()函数使用详细(301、404等错误设置)

    2023-11-02 17:28:23
  • python pandas中的agg函数用法

    2023-07-20 09:40:08
  • Python使用apscheduler模块设置定时任务的实现

    2021-05-01 05:01:54
  • 在网页中实现细线边框的两种方法

    2011-06-14 09:47:26
  • asp添加数据实现代码

    2011-02-05 10:42:00
  • 基本的页面设计元素布局比例

    2007-12-15 09:43:00
  • Python 异常处理Ⅳ过程图解

    2023-06-28 16:05:53
  • Python根据当前日期取去年同星期日期

    2021-09-14 15:01:48
  • JScript 运算符

    2007-08-22 16:22:00
  • Python Django 命名空间模式的实现

    2023-10-06 05:34:28
  • 减少新开窗口提升可访问性

    2009-04-17 13:56:00
  • Django缓存Cache使用详解

    2023-09-06 02:16:33
  • Python不使用int()函数把字符串转换为数字的方法

    2022-04-22 02:32:33
  • Python流程控制 while循环实现解析

    2023-02-07 04:16:33
  • Access报错:文件共享锁定数溢出

    2009-03-21 18:32:00
  • 2007淘宝UED招聘题解(前端开发部分)

    2007-11-24 10:32:00
  • python实现去除空格及tab换行符的方法

    2023-09-27 08:16:05
  • python Pexpect模块的使用

    2023-01-23 20:54:58
  • Python读取系统文件夹内所有文件并统计数量的方法

    2021-11-14 07:39:28
  • python openvc 裁剪、剪切图片 提取图片的行和列

    2022-07-03 15:29:40
  • asp之家 网络编程 m.aspxhome.com