本文主要是介绍雨滴,美丽的雨滴,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
原程序是别人的,我只是加了GIF录制。
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 3 13:17:50 2017@author: jiangyl
"""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 transparntcolor[:, 3] = np.maximum(0, color[:,3]-1.0/n)# Each ring is made largersize += (size_max - size_min) / n# Reset specific ringi = frame % 50pos[i] = np.random.uniform(0, 1, 2)size[i] = size_mincolor[i, 3] = 1# Update scatter objectscat.set_edgecolors(color)scat.set_sizes(size)scat.set_offsets(pos)# Return the modified objectreturn scat,anim = animation.FuncAnimation(fig, update, interval=30, blit=True, frames=80)
anim.save('snow.gif', fps=30, writer='imagemagick')
print("ok")
plt.show()
要使用IMAGEMAGICK需安装插件,我试了一下,用最新版的制作GIF不成功,用6.9.8的就可以。
链接见:
http://www.imagemagick.org/download/binaries/
这篇关于雨滴,美丽的雨滴的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!