小編給大家分享一下python如何實(shí)現(xiàn)雨滴下落到地面效果,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
創(chuàng)新互聯(lián)自2013年創(chuàng)立以來(lái),是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元渭源做網(wǎng)站,已為上家服務(wù),為渭源各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:18980820575具體內(nèi)容如下
本程序在Windows 64位操作系統(tǒng)下,安裝的是Anaconda3-4.2.0
import numpy as np import matplotlib.pyplot as plt from matplotlib import animation # New figure with white background fig = plt.figure(figsize=(6,6), facecolor='white') # New axis over the whole figure, no frame and a 1:1 aspect ratio ax = fig.add_axes([0, 0, 1, 1], frameon=False, aspect=1) # Number of ring n = 50 size_min = 50 size_max = 50 ** 2 # Ring position pos = np.random.uniform(0, 1, (n,2)) # Ring colors color = np.ones((n,4)) * (0,0,0,1) # Alpha color channel geos from 0(transparent) to 1(opaque) color[:,3] = np.linspace(0, 1, n) # Ring sizes size = np.linspace(size_min, size_max, n) # Scatter plot scat = ax.scatter(pos[:,0], pos[:,1], s=size, lw=0.5, edgecolors=color, facecolors='None') # Ensure limits are [0,1] and remove ticks ax.set_xlim(0, 1), ax.set_xticks([]) ax.set_ylim(0, 1), ax.set_yticks([]) def update(frame): global pos, color, size # Every ring is made more transparnt color[:, 3] = np.maximum(0, color[:,3]-1.0/n) # Each ring is made larger size += (size_max - size_min) / n # Reset specific ring i = frame % 50 pos[i] = np.random.uniform(0, 1, 2) size[i] = size_min color[i, 3] = 1 # Update scatter object scat.set_edgecolors(color) scat.set_sizes(size) scat.set_offsets(pos) # Return the modified object return scat, anim = animation.FuncAnimation(fig, update, interval=10, blit=True, frames=200) plt.show()
效果圖:
看完了這篇文章,相信你對(duì)“python如何實(shí)現(xiàn)雨滴下落到地面效果”有了一定的了解,如果想了解更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!