亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

微信跳一跳python自動代碼解讀1.0

 更新時間:2018年01月12日 11:53:51   作者:Big_Head_  
這篇文章主要為大家詳細(xì)介紹了微信跳一跳python自動代碼解讀1.0,具有一定的參考價值,感興趣的小伙伴們可以參考一下

微信跳一跳自動代碼,具體內(nèi)容如下

那個跳一跳python“外掛”,有幾個python文件,其中有一個是得到截圖,然后鼠標(biāo)在圖片上點擊兩次,python窗口上會打印兩次鼠標(biāo)的位置,并且會跟上一行這兩個點之間的距離。

樣例

這個功能我先給除去獲取截屏,就說怎么在某張圖片上算出兩次點擊的距離。

首先,需要用到圖形模塊,PIL:

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

然后用圖形繪制模塊matplotlib來給出一個plot對象:

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

給這個對象加上剛剛打開圖片的標(biāo)簽:

plt.imshow(img, animated = True)

然后用matplotlib的canvas.mpl_connect函數(shù),將我們點擊的動作和圖片連接起來,這個函數(shù)的第二個參數(shù)要我們自己的寫。

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

在這個自定義的on_press函數(shù),我們要實現(xiàn)得到兩個點以后再算出距離。
那么我們就要有變量來儲存兩個點,臨時儲存點,來計算點擊了多少次,橫縱坐標(biāo)
分別用全局變量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里面,打印出當(dāng)前位置,然后將臨時的放入全局變量cor里面, 并且點擊次數(shù)+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)


當(dāng)點擊次數(shù)大于1的時候,就說明已經(jīng)儲存了兩個點了。
這里用的棧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()


最終效果:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論