Advertisement
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
- R1 = 8
- R2 = 8
- def circle(a, b, r):
- T = 100
- x, y = [0]*T, [0]*T
- for i,theta in enumerate(np.linspace(0,2*np.pi,T)):
- x[i] = a + r*np.cos(theta)
- y[i] = b + r*np.sin(theta)
- return x, y
- def gen():
- for theta in np.linspace(0,15*np.pi,500):
- k = R1/R2
- a = R2 * (k + 1)*(np.cos(theta) - np.cos((k + 1) * theta )/ (k + 1))
- b = R2 * (k + 1)*(np.sin(theta) - np.sin((k + 1) * theta )/ (k + 1))
- yield a, b, (R1+R2) * np.cos(theta), (R1+R2) * np.sin(theta)
- fig = plt.figure(figsize=(6, 3))
- ax = fig.add_subplot(111)
- ax.set_ylim(-20, 20)
- ax.set_xlim(-20, 20)
- ax.set_xlabel('x')
- ax.set_ylabel('y')
- ax.set_aspect('equal')
- #ax.grid()
- time_text = ax.text(0.05, 0.8, '', transform=ax.transAxes)
- cardiod, = ax.plot([], [], 'r-', lw=2)
- line, = ax.plot([], [], 'y-', lw=2)
- circle_line, = ax.plot([], [], 'g', lw=2)
- circle_static, = ax.plot([], [], 'g', lw=2)
- point, = ax.plot([], [], 'bo', ms=4)
- xx, yy = [], []
- def func(data):
- x, y, Rx, Ry = data
- xx.append(x)
- yy.append(y)
- cx, cy = circle(Rx, Ry, R2)
- c1_x, c1_y = circle(0, 0, R1)
- cardiod.set_data(xx, yy)
- line.set_data((x, Rx), (y, Ry))
- circle_line.set_data(cx, cy)
- circle_static.set_data(c1_x, c1_y)
- point.set_data(x, y)
- ani = animation.FuncAnimation(fig, func, gen, blit=False, interval=50)
- plt.show()
- # fn = 'cacloid_FuncAnimation'
- # #ani.save('%s.mp4'%(fn), writer='ffmpeg', fps=1000/50)
- # xx, yy = [], []
- # ani.save('%s.gif'%(fn), writer='imagemagick', fps=1000/50)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement