Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from matplotlib.animation import ArtistAnimation
  4. fig = plt.figure()
  5. def circle_func(x_centre_point, y_centre_point, r, n):
  6. x = np.zeros(n)
  7. y = np.zeros(n)
  8. for i in range(0, n, 1):
  9. alpha = np.linspace(0, 2*np.pi, n)
  10. x[i] = x_centre_point + r * np.cos(alpha[i])
  11. y[i] = y_centre_point + r * np.sin(alpha[i])
  12. return x, y
  13. thetas = np.linspace(0, 4*np.pi, 100)
  14. r = 1
  15. cycloid_x = r * (thetas - np.sin(thetas))
  16. cycloid_y = r * (1 - np.cos(thetas))
  17. x_centre_move = r * thetas
  18. anim_list = []
  19. n = 100
  20. for i in range(0, n, 1):
  21. x, y = circle_func(x_centre_move[i], r, r, n)
  22. circle, = plt.plot(x, y, 'g-', lw=2)
  23. cycloid, = plt.plot(cycloid_x[:i+1], cycloid_y[:i+1], 'r-', lw=2)
  24. point, = plt.plot(cycloid_x[i], cycloid_y[i], 'bo', markersize=4)
  25. anim_list.append([circle, cycloid, point])
  26. ani = ArtistAnimation(fig, anim_list, interval=50)
  27. plt.axes().set_aspect('equal')
  28. ani.save('anim.gif')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement