Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from matplotlib import animation
  4. %matplotlib notebook
  5.  
  6. x = np.linspace(-7,7,50)
  7. y = np.linspace(-7,7,50)
  8.  
  9. xx, yy = np.meshgrid(x,y)
  10.  
  11. points = np.c_[xx.ravel(),yy.ravel()]
  12. sizes = abs(np.sin(points[:,0]) + np.sin(points[:,1])) * 14 + 5
  13. colours = np.log10(abs(points[:,0]/points[:,1]))
  14.  
  15. points[:,0] += np.sin(points[:,1])
  16.  
  17. fig = plt.figure(figsize=(7,7))
  18. ax = fig.add_axes([0,0,1,1], frameon=False)
  19. ax.set_xlim((-5,5))
  20. ax.set_ylim((-5,5))
  21. scat = ax.scatter(points[:,0],points[:,1], s=sizes, c=colours, alpha=0.8)
  22.  
  23.  
  24. def update(frame_number):
  25.  
  26.     new_position = points
  27.    
  28.     new_position[:,0] += np.sin((np.sin(frame_number/11)*(sizes-6))/7)/20
  29.     new_position[:,1] += np.tan((np.cos(frame_number/9)*(abs(colours)**0.25)*3)/7)/15
  30.     scat.set_offsets(new_position)
  31.  
  32. anim = animation.FuncAnimation(fig, update, interval=50, frames=300)
  33.  
  34. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement