python實(shí)現(xiàn)雨滴下落到地面效果
本文實(shí)例為大家分享了python實(shí)現(xiàn)雨滴下落到地面效果的具體代碼,供大家參考,具體內(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()
效果圖:
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
用Pelican搭建一個(gè)極簡(jiǎn)靜態(tài)博客系統(tǒng)過程解析
這篇文章主要介紹了用Pelican搭建一個(gè)極簡(jiǎn)靜態(tài)博客系統(tǒng)過程解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-08-08Python turtle庫(kù)的畫筆控制說(shuō)明
這篇文章主要介紹了Python turtle庫(kù)的畫筆控制說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來(lái)看看吧2020-06-06python數(shù)據(jù)庫(kù)操作--數(shù)據(jù)庫(kù)使用概述
這篇文章主要介紹了python中使用mysql數(shù)據(jù)庫(kù)詳細(xì)介紹,本文起講解了安裝mysql、安裝MySQL-python、mysql 的基本操作、python 操作mysql數(shù)據(jù)庫(kù)基礎(chǔ)等內(nèi)容,需要的朋友可以參考下2021-08-08運(yùn)行django項(xiàng)目指定IP和端口的方法
今天小編就為大家分享一篇運(yùn)行django項(xiàng)目指定IP和端口的方法。具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來(lái)看看吧2018-05-05Python繪制三角函數(shù)圖(sin\cos\tan)并標(biāo)注特定范圍的例子
今天小編就為大家分享一篇Python繪制三角函數(shù)圖(sin\cos\tan)并標(biāo)注特定范圍的例子,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來(lái)看看吧2019-12-12flask-SQLALchemy連接數(shù)據(jù)庫(kù)的實(shí)現(xiàn)示例
sqlalchemy是數(shù)據(jù)庫(kù)的orm框架,讓我們操作數(shù)據(jù)庫(kù)的時(shí)候不要再用sql語(yǔ)句了,本文就介紹了flask-SQLALchemy連接數(shù)據(jù)庫(kù)的實(shí)現(xiàn)示例,感興趣的可以了解一下2022-06-06分析Python中設(shè)計(jì)模式之Decorator裝飾器模式的要點(diǎn)
這篇文章主要介紹了Python中設(shè)計(jì)模式之Decorator裝飾器模式模式,文中詳細(xì)地講解了裝飾對(duì)象的相關(guān)加鎖問題,需要的朋友可以參考下2016-03-03