介绍
小编给大家分享一下python如何实现雨滴下落到地面效果,希望大家阅读完这篇文章之后都有所收获、下面让我们一起去探讨吧!
具体内容如下
本程序在Windows 64位操作系统下,安装的是Anaconda3-4.2.0
import numpy as np import matplotlib.pyplot  as plt 得到matplotlib import  animation , #,New figure  with white background 时间=fig plt.figure (figsize=(6,6), facecolor=& # 39;白色# 39;), , #,New axis 配套;从而whole 图,,no frame 以及a 1:1 aspect ratio 时间=ax fig.add_axes ([0, 0, 1, 1),, frameon=False,,=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 得到0(透明),用1(不透明的), 颜色(: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=大小,lw=0.5, edgecolors=颜色,facecolors=& # 39;没有# 39;), , #,Ensure limits 断开连接;[0,1],以及remove ticks ax.set_xlim (0, 1), ax.set_xticks ([]), ax.set_ylim (0, 1), ax.set_yticks ([]), , def 更新(帧):, global 才能;pos,,颜色,,size , #,才能Every ring is made more transparnt 颜色才能(:,,3),=,np.maximum(0),颜色(:3)-1.0/n), , #,才能Each ring is made larger size 才能+=,(size_max 作用;size_min),/, n , #,才能Reset specific ring 小姐:才能=,frame %, 50, pos才能[我],=,np.random.uniform (0, 1, 2), 大小才能[我],=,size_min 颜色才能[3]我也,=,1, , #,才能Update scatter object scat.set_edgecolors才能(颜色), scat.set_sizes才能(大小), scat.set_offsets才能(pos), , #,才能Return 从而modified object 嘘,return 才能; , 时间=anim animation.FuncAnimation(无花果、,更新,间隔=10,,=True,贴图,?200), plt.show ()
效果图:
看完了这篇文章,相信你对“python如何实现雨滴下落到地面效果”有了一定的了解,如果想了解更多相关知识,欢迎关注行业资讯频道,感谢各位的阅读!