```python
import turtle
def draw_heart():
penup()
goto(0, -100)
pendown()
color('red')
begin_fill()
setheading(150)
circle(200, 90)
left(90)
circle(200, 90)
end_fill()
hideturtle()
draw_heart()
done()
```
代码解释:
导入turtle库:
`import turtle`
定义绘制爱心的函数:
`def draw_heart():`
移动画笔到起始位置:
`penup()` 和 `goto(0, -100)`
设置画笔属性:
`pendown()` 和 `color('red')`
开始填充颜色:
`begin_fill()`
设置画笔方向:
`setheading(150)`
绘制两个半圆:
`circle(200, 90)` 和 `left(90)` 再 `circle(200, 90)`
结束填充颜色:
`end_fill()`
隐藏画笔:
`hideturtle()`
调用绘制爱心的函数:
`draw_heart()`
保持窗口打开:
`done()`
运行这段代码,你将在屏幕上看到一个红色的爱心形状。你可以根据需要调整参数,比如颜色、大小和位置。