请用python写一个画爱心代码
时间: 2024-02-02 20:03:23 浏览: 78
python画爱心代码
以下是Python画爱心的代码:
```python
import turtle
# 设置画布大小
canvas = turtle.Screen()
canvas.setup(width=400, height=400)
# 设置画笔
pen = turtle.Turtle()
pen.hideturtle()
pen.speed(0)
pen.pensize(3)
# 画红色爱心
pen.color('red')
pen.fillcolor('red')
pen.begin_fill()
pen.left(45)
pen.forward(100)
pen.circle(50, 180)
pen.right(90)
pen.circle(50, 180)
pen.forward(100)
pen.end_fill()
# 画白色爱心
pen.color('white')
pen.fillcolor('white')
pen.begin_fill()
pen.left(45)
pen.forward(70)
pen.circle(25, 180)
pen.right(90)
pen.circle(25, 180)
pen.forward(70)
pen.end_fill()
# 显示结果
turtle.done()
```
运行代码后,会在画布上画出一个红色和白色相间的爱心。
阅读全文