用python写一个动态爱心
时间: 2024-04-29 09:25:08 浏览: 139
python 动态绘制爱心的示例
5星 · 资源好评率100%
好的,以下是Python代码,可以绘制一个动态的爱心:
```python
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
t = np.linspace(0, 2 * np.pi, 100)
x = 16 * np.sin(t) ** 3
y = 13 * np.cos(t) - 5 * np.cos(2 * t) - 2 * np.cos(3 * t) - np.cos(4 * t)
line, = ax.plot(x, y)
def animate(i):
new_y = y * (1 + 0.1 * i)
line.set_ydata(new_y)
return line,
ani = animation.FuncAnimation(fig, animate, frames=100, interval=50, blit=True)
plt.show()
```
希望对你有帮助!
阅读全文