微信跳一跳python自动代码解读1.0
作者:Big_Head_ 发布时间:2022-11-30 05:31:49
标签: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()
最终效果:
来源:http://blog.csdn.net/Big_Head_/article/details/78976302
0
投稿
猜你喜欢
- replaceChild(a,b)是用来替换文档中的已有元素的 参数a:要插入的节点, 参数b:要替换的节点 var oDiv = docu
- 本文实例讲述了python有证书的加密解密实现方法。分享给大家供大家参考。具体实现方法如下:最近在做python的加解密工作,同时加完密的串
- 本文主要研究的是flask使用session保存登录状态及拦截未登录请求的相关内容,具体介绍如下。前端请求form:<form act
- MySQL 触发器MySQL 数据库中触发器是一个特殊的存储过程,不同的是执行存储过程要使用 CALL 语句来调用,而触发器的执行不需要使用
- 引入函数既可以嵌套定义也可以嵌套调用。嵌套定义指的是在定义一个函数时在该函数内部定义另一个函数;嵌套调用指的是在调用一个函数的过程中函数内部
- 对python中的控制条件、循环和跳出详解代码缩进(代码块):python用缩进表示代码块,没有其他语言的大括号缩进是强制检查,整个代码缩进
- 本文实例讲述了python实现telnet客户端的方法。分享给大家供大家参考。具体如下:python实现的telnet客户端程序,pytho
- 本文实例为大家分享了python+pygame实现坦克大战的具体代码,供大家参考,具体内容如下一、首先导入pygame库二、源码分享#cod
- //定义一个对象数组 var data = [{ name: "jiang", age: 22 }, { name: &
- 必备环境废话每年回家都要帮我爸下些音乐,这对我来说都是轻车熟路!可当我打开网易云点击下载按钮的时候,可惜已物是人非啦!开个 VIP 其实也不
- 基本思路:首先用开发者工具找到需要提取数据的标签列利用xpath定位需要提取数据的列表然后再逐个提取相应的数据:保存数据到csv:利用开发者
- Go 程序运行时,有些场景下会导致进程进入某个“高点”,然后就再也下不来了。比如,多年前曹大写过的一
- 本文讲述使用JSP实现用户登录,包括用户登录、注册和退出功能等。1.系统用例图2.页面流程图3.数据库设计本例使用oracle数据库创建用户
- 在开发工具、数据库设计、应用程序的结构、查询设计、接口选择等方面有多种选择,这取决于特定的应用需求以及开发队伍的技能。本文以SQL Serv
- 本篇阅读的代码片段来自于30-seconds-of-python。1、average_bydef average_by(lst, fn=la
- Python虚拟机注:本篇是根据教程学习记录的笔记,部分内容与教程是相同的,因为转载需要填链接,但是没有,所以填的原创,如果侵权会直接删除。
- 微信入口绑定,微信事件处理,微信API全部操作包含在这些文件中。内容有:微信摇一摇接口/微信多客服接口/微信支付接口/微信红包接口/微信卡券
- 本文实例讲述了php+html5基于websocket实现聊天室的方法。分享给大家供大家参考。具体如下:html5的websocket 实现
- 前言sched是Python的内置模块,用于事件调度,可在安全的在多线程环境中轻松实现定时任务。sched是一种调度(延时处理机制)。sch
- 1. 文件锁脚本启动前检查特定文件是否存在,不存在就启动并新建文件,脚本结束后删掉特定文件。通过文件的判断来确定脚本是否正在执行。方法实现也