利用turtle库绘制笑脸表情(大小、颜色、位置等自己设定)。
时间: 2023-04-02 14:00:32 浏览: 265
好的,我可以回答这个问题。以下是利用turtle库绘制笑脸表情的代码示例:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(600, 600)
turtle.bgcolor("lightblue")
# 绘制圆形脸底部
turtle.penup()
turtle.goto(, -200)
turtle.pendown()
turtle.pensize(5)
turtle.pencolor("black")
turtle.fillcolor("yellow")
turtle.begin_fill()
turtle.circle(200)
turtle.end_fill()
# 绘制左眼
turtle.penup()
turtle.goto(-80, 50)
turtle.pendown()
turtle.pencolor("black")
turtle.fillcolor("white")
turtle.begin_fill()
turtle.circle(40)
turtle.end_fill()
turtle.penup()
turtle.goto(-60, 70)
turtle.pendown()
turtle.fillcolor("black")
turtle.begin_fill()
turtle.circle(15)
turtle.end_fill()
# 绘制右眼
turtle.penup()
turtle.goto(80, 50)
turtle.pendown()
turtle.pencolor("black")
turtle.fillcolor("white")
turtle.begin_fill()
turtle.circle(40)
turtle.end_fill()
turtle.penup()
turtle.goto(100, 70)
turtle.pendown()
turtle.fillcolor("black")
turtle.begin_fill()
turtle.circle(15)
turtle.end_fill()
# 绘制嘴巴
turtle.penup()
turtle.goto(-100, -50)
turtle.pendown()
turtle.pencolor("black")
turtle.right(90)
turtle.circle(100, 180)
# 隐藏画笔
turtle.hideturtle()
# 显示绘图窗口
turtle.done()
```
这段代码可以绘制一个黄色的圆形脸底部,两个白色的眼睛,黑色的瞳孔和一个笑脸的嘴巴。你可以根据自己的需要调整大小、颜色和位置等参数。
阅读全文