Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- import matplotlib.animation as animation
- from IPython.display import HTML
- fig, ax = plt.subplots()
- def update(num):
- if len(round_circles) > 0:
- round_circles.pop().remove()
- epicycloids.pop().remove()
- points.pop().remove()
- round_circle, = plt.plot(x_move[num]+xm, y_move[num]+ym, 'b-', lw=2)
- epicycloid, = plt.plot(x[:num+1] ,y[:num+1], 'g-', lw=2)
- point, = plt.plot(x[num], y[num], 'ko', markersize=4)
- round_circles.append(round_circle)
- epicycloids.append(epicycloid)
- points.append(point)
- theta_str = r'$\theta=$'
- ax.set_title(theta_str + str(theta[num]/np.pi)[:4] + str(r' $\pi$'))
- ax.grid()
- ax.set_xlabel('x')
- ax.set_ylabel('y')
- ax.set_aspect('equal')
- #plot data
- theta = np.linspace(0, 4*np.pi,200)
- phi= np.linspace(0,2*np.pi,100)
- rc=5
- rm=2
- x = (rc+rm)*np.cos(theta)-rm*np.cos(theta*((rc+rm)/rm))
- y = (rc+rm)*np.sin(theta)-rm*np.sin(theta*((rc+rm)/rm))
- epicycloids=[]
- points=[]
- xm = rm*np.cos(phi)
- ym = rm*np.sin(phi)
- round_circles =[]
- xc = rc*np.cos(phi)
- yc = rc*np.sin(phi)
- plt.plot(xc, yc, 'k-', lw=2)#center_circle
- x_move = (rc+rm)*np.cos(theta)
- y_move = (rc+rm)*np.sin(theta)
- ani = animation.FuncAnimation(fig, update, 200, interval=100)
- HTML(ani.to_html5_video())
- #dpi=100
- #ani.save('episaikuroid.mp4', writer="ffmpeg",dpi=dpi)
Add Comment
Please, Sign In to add comment