Creates a second hand (clock) that rotates every second and makes one revolution in 60 seconds. Just drawing the second hand is boring, so the color of the clock should gradually change from blue to red in the range of 0 to 60 [s]. Finally, save it as a gif and you're done.
Use python's library for creating animations.
second_hand.py
%matplotlib nbagg
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import matplotlib.patches as pat
fig = plt.figure()
ax = plt.subplot()
def clock(i):
circle = [ax.add_patch(pat.Wedge(center=(0, 0), r=1, color=[0+i/60,0,1-i/60], theta1 = 95-i*(360/60), theta2 = 85-i*(360/60)))]
#center: center xy coordinates,r: wedge radius,color: Color specification in RGB(Each color 0~1),theta: Specify the wedge angle
#Note that we list circles. This is so that it can be added to imgs later.
return circle
#Add a clock for each second to the list imgs.
imgs=[]
for i in range(60):
imgs.append(clock(i))
ani = animation.ArtistAnimation(fig, imgs, interval=1000, repeat=True)
plt.axis("scaled")
plt.show()
ani.save("second_hand.gif", writer="imagemagick")#Save as gif
macOS Catalina jupyter-notebook
Recommended Posts