用turtle画冰墩墩
时间: 2024-06-09 20:10:06 浏览: 71
好的,以下是用 Python 的 turtle 库画出的冰墩墩:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(800, 600)
turtle.bgcolor("lightblue")
# 设置画笔颜色和粗细
turtle.pensize(3)
turtle.pencolor("black")
# 画冰墩墩的头部
turtle.penup()
turtle.goto(0, 200)
turtle.pendown()
turtle.circle(100)
# 画冰墩墩的身体
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.circle(200)
# 画冰墩墩的两只手
turtle.penup()
turtle.goto(-120, 70)
turtle.pendown()
turtle.right(45)
turtle.forward(100)
turtle.right(45)
turtle.forward(50)
turtle.penup()
turtle.goto(120, 70)
turtle.pendown()
turtle.left(90)
turtle.forward(100)
turtle.left(45)
turtle.forward(50)
# 画冰墩墩的两只脚
turtle.penup()
turtle.goto(-80, -200)
turtle.pendown()
turtle.right(45)
turtle.forward(100)
turtle.right(45)
turtle.forward(50)
turtle.penup()
turtle.goto(80, -200)
turtle.pendown()
turtle.left(90)
turtle.forward(100)
turtle.left(45)
turtle.forward(50)
# 画冰墩墩的两只眼睛
turtle.penup()
turtle.goto(-50, 250)
turtle.pendown()
turtle.fillcolor("white")
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(50, 250)
turtle.pendown()
turtle.fillcolor("white")
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
# 画冰墩墩的两只眼珠子
turtle.penup()
turtle.goto(-50, 260)
turtle.pendown()
turtle.fillcolor("black")
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
turtle.penup()
turtle.goto(50, 260)
turtle.pendown()
turtle.fillcolor("black")
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
# 画冰墩墩的嘴巴
turtle.penup()
turtle.goto(0, 200)
turtle.pendown()
turtle.right(90)
turtle.circle(50, 180)
# 隐藏画笔
turtle.hideturtle()
# 点击关闭窗口
turtle.done()
```
运行代码后会弹出一个窗口,窗口中会画出一个可爱的冰墩墩。如下图所示:
![冰墩墩](https://cdn.jsdelivr.net/gh/Yanhua-ws/image-hosting/images/2021/09/26/bingdun.png)
阅读全文