Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- from matplotlib.patches import Circle, Ellipse, Arc
- import matplotlib.animation as animation
- fig, ax = plt.subplots()
- head = Circle((0, 0), 1, facecolor='peachpuff', edgecolor='black', lw=2)
- right_eye = Circle((0.35, 0.35), 0.15, facecolor='white', edgecolor='black', lw=2)
- right_pupil = Circle((0.35, 0.35), 0.07, facecolor='black')
- left_eye = Ellipse((-0.35, 0.35), 0.3, 0.3, facecolor='white', edgecolor='black', lw=2)
- left_pupil = Circle((-0.35, 0.35), 0.07, facecolor='black')
- nose = Ellipse((0, 0.1), 0.2, 0.1, facecolor='sandybrown', edgecolor='black', lw=2)
- mouth = Arc((0, -0.2), 0.5, 0.3, angle=0, theta1=20, theta2=160, edgecolor='red', lw=2)
- left_eyebrow = Arc((-0.35, 0.55), 0.4, 0.2, angle=0, theta1=0, theta2=180, edgecolor='black', lw=2)
- right_eyebrow = Arc((0.35, 0.55), 0.4, 0.2, angle=0, theta1=0, theta2=180, edgecolor='black', lw=2)
- ax.add_patch(head)
- ax.add_patch(right_eye)
- ax.add_patch(right_pupil)
- ax.add_patch(left_eye)
- ax.add_patch(left_pupil)
- ax.add_patch(nose)
- ax.add_patch(mouth)
- ax.add_patch(left_eyebrow)
- ax.add_patch(right_eyebrow)
- ax.set_xlim(-1.2, 1.2)
- ax.set_ylim(-1.2, 1.2)
- ax.set_aspect('equal')
- ax.axis('off')
- def wink_scale(frame, period=30):
- t = (frame % period) / period
- if t < 0.2:
- return 1.0
- elif t < 0.3:
- return 1.0 - (t - 0.2) / 0.1
- elif t < 0.7:
- return 0.0
- elif t < 0.8:
- return (t - 0.7) / 0.1
- else:
- return 1.0
- def update(frame):
- scale = wink_scale(frame)
- new_height = 0.3 * scale if scale > 0 else 0.01
- left_eye.set_height(new_height)
- left_pupil.set_visible(scale > 0.5)
- return [left_eye, left_pupil]
- ani = animation.FuncAnimation(fig, update, frames=200, interval=50, blit=True)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement