pytion画跳动的爱心
时间: 2024-06-09 11:03:16 浏览: 10
Python可以使用turtle库来画图形,包括爱心。
以下是Python绘制跳动的爱心的代码:
```python
import turtle
import time
# 初始化turtle
t = turtle.Turtle()
t.hideturtle()
t.getscreen().bgcolor("#F5F5F5")
t.pensize(5)
# 设置爱心颜色和填充颜色
heart_color = "#FF1493"
fill_color = "#FFC0CB"
# 绘制爱心
def draw_heart():
t.color(heart_color)
t.fillcolor(fill_color)
t.begin_fill()
t.left(45)
t.forward(100)
t.circle(50, 180)
t.right(90)
t.circle(50, 180)
t.forward(100)
t.end_fill()
# 跳动的爱心效果
while True:
# 改变填充颜色实现跳动效果
if fill_color == "#FFC0CB":
fill_color = "#FF69B4"
else:
fill_color = "#FFC0CB"
draw_heart()
# 暂停0.5秒
time.sleep(0.5)
# 清空画布
t.clear()
```
运行代码后,将会在窗口中看到跳动的爱心。