Guest User

Untitled

a guest
Jul 3rd, 2015
329
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import numpy
  2. import matplotlib.pyplot as plt
  3. from matplotlib import animation
  4.  
  5. N_CIRCLES = 20
  6. N_FRAMES = 150
  7.  
  8. T_CIRCLES = numpy.linspace(0,10,N_CIRCLES)
  9. T = numpy.linspace(0,10,N_FRAMES)
  10.  
  11. fig = plt.figure(figsize=(3,3), dpi=100)
  12. ax = plt.axes(xlim=(-5,10), ylim=(-7.5,7.5))
  13.  
  14. emitter = plt.Circle((0,0),.3,color='k', )
  15. ax.add_patch(emitter)
  16.  
  17.  
  18. observer = plt.Circle((7,-2),.3,color='k', )
  19. ax.add_patch(observer)
  20.  
  21.  
  22. plt.axis('off')
  23. circles = []
  24. for t_i in range(N_CIRCLES):
  25.     color='k'
  26.     if (t_i==0):
  27.         color = 'r'
  28.     elif (t_i==1):
  29.         color = 'b'
  30.     circles.append(plt.Circle((2*T_CIRCLES[t_i],0),0,color=color, fill=False))
  31.     ax.add_patch(circles[-1])
  32.  
  33. def func(nframe):
  34.     print nframe
  35.     emitter.center = (2*T[nframe], 0)
  36.     for t_i in range(N_CIRCLES):
  37.         circles[t_i].radius = max(0,T[nframe]-T_CIRCLES[t_i])
  38.     return circles[0], circles[1],
  39.  
  40. ani = animation.FuncAnimation(fig, func, N_FRAMES)
  41. ani.save('plotcircles.gif', writer='imagemagick', fps=25, dpi=100)
  42.  
  43. #plt.show()
RAW Paste Data