用python的turtle库画一个人脸
时间: 2024-04-20 20:16:26 浏览: 126
Python如何使用turtle库绘制图形
好的,以下是用 Python 的 turtle 库画一个人脸的代码:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(600, 600)
turtle.bgcolor("#F0EAD6")
# 画圆形的脸
turtle.penup()
turtle.goto(0, -200)
turtle.pendown()
turtle.fillcolor("#F8E4C9")
turtle.begin_fill()
turtle.circle(200)
turtle.end_fill()
# 左眼
turtle.penup()
turtle.goto(-80, 80)
turtle.pendown()
turtle.fillcolor("#FFFFFF")
turtle.begin_fill()
turtle.circle(40)
turtle.end_fill()
turtle.penup()
turtle.goto(-65, 100)
turtle.pendown()
turtle.fillcolor("#000000")
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
# 右眼
turtle.penup()
turtle.goto(80, 80)
turtle.pendown()
turtle.fillcolor("#FFFFFF")
turtle.begin_fill()
turtle.circle(40)
turtle.end_fill()
turtle.penup()
turtle.goto(95, 100)
turtle.pendown()
turtle.fillcolor("#000000")
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
# 嘴巴
turtle.penup()
turtle.goto(-100, -40)
turtle.pendown()
turtle.fillcolor("#FFC0CB")
turtle.begin_fill()
turtle.circle(60, 180)
turtle.end_fill()
# 鼻子
turtle.penup()
turtle.goto(0, 40)
turtle.pendown()
turtle.fillcolor("#FFC0CB")
turtle.begin_fill()
turtle.circle(40)
turtle.end_fill()
turtle.penup()
turtle.goto(0, 20)
turtle.pendown()
turtle.fillcolor("#FF69B4")
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
# 完成
turtle.hideturtle()
turtle.done()
```
运行以上代码,可以得到如下图所示的人脸:
![人脸](https://cdn.jsdelivr.net/gh/Yijiujiu/MarkdownPhotos//small/Python/Python-turtle-face.png)
阅读全文