的另一种方式实现的衰落对地块的序列路径是改变使用.set_alpha()
方法绘制项目的阿尔法值,如果它是可用于特定您正在使用的绘图方法。
您可以通过将您正在使用的特定绘图功能的输出(即绘图中的“手柄”)附加到列表中来完成此操作。然后,在每个新图之前,您可以找到并减少该列表中每个现有项目的alpha值。
在以下示例中,将使用.remove()
从图中删除其alpha值下降超过某个点的项目,然后将它们的句柄从列表中删除。
import pylab as pl
#Set a decay constant; create a list to store plot handles; create figure.
DECAY = 2.0
plot_handles = []
pl.figure()
#Specific to this example: store x values for plotting sinusoid function
x_axis=pl.linspace(0 , 2 * pl.pi , 100)
#Specific to this example: cycle 50 times through 16 different sinusoid
frame_counter = 0
for phase in pl.linspace(0 , 2 * pl.pi * 50 , 16 * 50):
#Reduce alpha for each old item, and remove
for handle in plot_handles:
alpha = handle.get_alpha()
if alpha/DECAY > 0.01 :
handle.set_alpha(alpha/DECAY)
else:
handle.remove()
plot_handles.remove(handle)
#Add new output of calling plot function to list of handles
plot_handles += pl.plot(pl.sin(x_axis + phase) , 'bo')
#Redraw figure
pl.draw()
#Save image
pl.savefig('frame_' + str(frame_counter).zfill(8) + '.png')
frame_counter += 1