python用turtle画熊猫
时间: 2023-10-19 18:07:47 浏览: 214
python用turtle画出给定图片的图像、校徽等复杂图像都可以
5星 · 资源好评率100%
好的,以下是用Python的turtle库画熊猫的代码:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(800, 600)
turtle.bgcolor("#FFFFFF")
# 设置画笔
turtle.penup()
turtle.speed(10)
# 画左耳朵
turtle.goto(-100, 100)
turtle.pendown()
turtle.fillcolor("#000000")
turtle.begin_fill()
turtle.circle(60, 180)
turtle.right(90)
turtle.forward(120)
turtle.right(90)
turtle.circle(-60, 180)
turtle.end_fill()
# 画右耳朵
turtle.penup()
turtle.goto(100, 100)
turtle.pendown()
turtle.begin_fill()
turtle.circle(-60, 180)
turtle.left(90)
turtle.forward(120)
turtle.left(90)
turtle.circle(60, 180)
turtle.end_fill()
# 画脸
turtle.penup()
turtle.goto(0, -50)
turtle.pendown()
turtle.begin_fill()
turtle.circle(150)
turtle.end_fill()
# 画鼻子
turtle.penup()
turtle.goto(0, 50)
turtle.pendown()
turtle.fillcolor("#000000")
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
# 画眼睛
turtle.penup()
turtle.goto(-60, 120)
turtle.pendown()
turtle.fillcolor("#000000")
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
turtle.penup()
turtle.goto(-45, 135)
turtle.pendown()
turtle.fillcolor("#FFFFFF")
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
turtle.penup()
turtle.goto(60, 120)
turtle.pendown()
turtle.fillcolor("#000000")
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
turtle.penup()
turtle.goto(75, 135)
turtle.pendown()
turtle.fillcolor("#FFFFFF")
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
# 画嘴巴
turtle.penup()
turtle.goto(-60, 40)
turtle.pendown()
turtle.right(60)
turtle.circle(80, 120)
# 隐藏画笔
turtle.hideturtle()
turtle.done()
```
运行代码后,会在画布上绘制出一个可爱的熊猫图案。
阅读全文