import matplotlib
import matplotlib.pyplot as plt
import moviepy.editor as mpymatplotlib.rcParams['font.family'] = 'SimHei'
positions = [(0, 0), (1 / 4, 1 / 4), (1 / 3, 1 / 4), (1 / 2, 1 / 4), (2 / 3, 1 / 4),(3 / 4, 1 / 4), (1, 1 / 4), (5 / 4, 1 / 4), (4 / 3, 1 / 4), (3 / 2, 1 / 4), (2, 0)
]
radius = 1
text = "人有悲欢离合\n月有阴晴圆缺\n此事古难全\n但愿人长久\n千里共婵娟"
for index, position in enumerate(positions):fig, ax = plt.subplots()circle2 = plt.Circle((2 * radius, 0), radius, color='#E1E19A', fill=True)ax.add_artist(circle2)circle1 = plt.Circle(position, radius, color='white', fill=True)ax.add_artist(circle1)ax.set_xlim(-1, 3)ax.set_ylim(-1, 1)ax.set_aspect('equal') ax.axis('off') ax.text(-0.8, 0.5, text, fontsize=12, ha='left', va='center', color='black', wrap=True)plt.savefig(f'frame_{index:03d}.png', bbox_inches='tight', pad_inches=0)plt.close(fig)
clips = []
for i in range(len(positions)):clip = mpy.ImageClip(f'frame_{i:03d}.png').set_duration(0.1) clips.append(clip)
video = mpy.concatenate_videoclips(clips, method='compose')
video.write_gif("circle_animation1.gif", fps=10)
video.write_videofile("circle_animation_with_text1.mp4", fps=10)