帮我用python画一个会动的爱心
时间: 2023-03-27 16:01:16 浏览: 98
python 动态绘制爱心的示例
5星 · 资源好评率100%
好的,我可以帮您用 Python 画一个会动的爱心。以下是代码示例:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(600, 600)
turtle.bgcolor('black')
# 设置画笔颜色和粗细
turtle.color('red', 'pink')
turtle.pensize(3)
# 定义爱心函数
def draw_heart():
turtle.begin_fill()
turtle.left(45)
turtle.forward(120)
turtle.circle(60, 180)
turtle.right(90)
turtle.circle(60, 180)
turtle.forward(120)
turtle.end_fill()
# 循环绘制爱心
while True:
turtle.clear()
turtle.penup()
turtle.goto(, 100)
turtle.pendown()
draw_heart()
turtle.penup()
turtle.goto(, )
turtle.pendown()
turtle.write("I love you", align="center", font=("Arial", 24, "normal"))
turtle.penup()
turtle.goto(, -100)
turtle.pendown()
draw_heart()
turtle.penup()
turtle.goto(, )
turtle.pendown()
turtle.write("I love you", align="center", font=("Arial", 24, "normal"))
turtle.penup()
turtle.goto(, )
turtle.pendown()
turtle.right(10)
# 点击关闭窗口
turtle.done()
```
运行代码后,您将看到一个会动的爱心。希望您喜欢!
阅读全文