Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- from matplotlib.animation import ArtistAnimation
- fig = plt.figure()
- def circle_func(x_centre_point, y_centre_point, r, n):
- x = np.zeros(n)
- y = np.zeros(n)
- for i in range(0, n, 1):
- alpha = np.linspace(0, 2*np.pi, n)
- x[i] = x_centre_point + r * np.cos(alpha[i])
- y[i] = y_centre_point + r * np.sin(alpha[i])
- return x, y
- thetas = np.linspace(0, 4*np.pi, 100)
- r = 1
- cycloid_x = r * (thetas - np.sin(thetas))
- cycloid_y = r * (1 - np.cos(thetas))
- x_centre_move = r * thetas
- anim_list = []
- n = 100
- for i in range(0, n, 1):
- x, y = circle_func(x_centre_move[i], r, r, n)
- circle, = plt.plot(x, y, 'g-', lw=2)
- cycloid, = plt.plot(cycloid_x[:i+1], cycloid_y[:i+1], 'r-', lw=2)
- point, = plt.plot(cycloid_x[i], cycloid_y[i], 'bo', markersize=4)
- anim_list.append([circle, cycloid, point])
- ani = ArtistAnimation(fig, anim_list, interval=50)
- plt.axes().set_aspect('equal')
- ani.save('anim.gif')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement