turtle库画一个人物头像的代码
时间: 2023-04-07 22:03:34 浏览: 110
以下是使用turtle库画一个人物头像的代码:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(500, 500)
turtle.bgcolor("white")
# 画头像的脸部
turtle.penup()
turtle.goto(0, -100)
turtle.pendown()
turtle.begin_fill()
turtle.circle(100)
turtle.end_fill()
# 画头像的眼睛
turtle.penup()
turtle.goto(-40, 20)
turtle.pendown()
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(40, 20)
turtle.pendown()
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
# 画头像的嘴巴
turtle.penup()
turtle.goto(-60, -30)
turtle.pendown()
turtle.right(45)
turtle.circle(80, 90)
# 画头像的耳朵
turtle.penup()
turtle.goto(-120, 0)
turtle.pendown()
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
turtle.penup()
turtle.goto(120, 0)
turtle.pendown()
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 等待用户关闭窗口
turtle.done()
```
希望这个代码能够帮到你!
阅读全文