Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. import math
  2. import matplotlib.pyplot as plt
  3. import matplotlib.animation as animation
  4. import numpy as np
  5. from matplotlib.widgets import Slider, Button, RadioButtons
  6. from matplotlib import style
  7.  
  8. style.use('seaborn-poster')
  9. def _update_plot(i, fig, scat, l,l2):
  10.  
  11. M = ((math.sin(math.radians(i))*7.5)-(math.sin(math.radians(i/2))*9))/((math.cos(math.radians(i))*7.5)-(math.cos(math.radians(i/2))*9))
  12.  
  13. g = M*(15-(math.cos(math.radians(i/2))*9))+(math.sin(math.radians(i/2))*9)
  14.  
  15.  
  16. scat.set_offsets(([math.cos(math.radians(i))*7.5, math.sin(math.radians(i))*7.5], [math.cos(math.radians(i/2))*9, math.sin(math.radians(i/2))*9], [0, 0]))
  17.  
  18. if (i>=540) or (i<=180):
  19. l.set_data(([math.cos(math.radians(i))*7.5,math.cos(math.radians(i/2))*9],[math.sin(math.radians(i))*7.5,math.sin(math.radians(i/2))*9]))
  20. l2.set_data(([math.cos(math.radians(i/2))*9,15],[math.sin(math.radians(i/2))*9,g]))
  21. else:
  22. l.set_data(([0,0],[0,0]))
  23. l2.set_data(([0,0],[0,0]))
  24.  
  25.  
  26. return [scat,l,l2]
  27.  
  28.  
  29.  
  30. fig = plt.figure()
  31.  
  32.  
  33. x = [0]
  34. y = [0]
  35.  
  36. ax = fig.add_subplot(111)
  37. ax.set_aspect('equal')
  38. ax.grid(True, linestyle = '-', color = '0.10')
  39. ax.set_xlim([-15, 15])
  40. ax.set_ylim([-15, 15])
  41.  
  42. l, = plt.plot([],[], '-', zorder=1)
  43. l2, = plt.plot([],[], '-', zorder=2)
  44. scat = plt.scatter(x, y, c = x, zorder=3)
  45. scat.set_alpha(0.8)
  46.  
  47. anim = animation.FuncAnimation(fig, _update_plot, fargs = (fig, scat, l,l2),
  48. frames = 720, interval = 10)
  49.  
  50. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement