Python画一只乌龟
时间: 2023-04-12 08:00:58 浏览: 116
python-海龟绘图
好的,以下是Python画一只乌龟的代码:
```python
import turtle
# 创建画布和画笔
canvas = turtle.Screen()
pen = turtle.Turtle()
# 画乌龟的头
pen.fillcolor("green")
pen.begin_fill()
pen.circle(100)
pen.end_fill()
# 画乌龟的眼睛
pen.penup()
pen.goto(-30, 120)
pen.pendown()
pen.fillcolor("white")
pen.begin_fill()
pen.circle(20)
pen.end_fill()
pen.penup()
pen.goto(-30, 130)
pen.pendown()
pen.fillcolor("black")
pen.begin_fill()
pen.circle(10)
pen.end_fill()
pen.penup()
pen.goto(30, 120)
pen.pendown()
pen.fillcolor("white")
pen.begin_fill()
pen.circle(20)
pen.end_fill()
pen.penup()
pen.goto(30, 130)
pen.pendown()
pen.fillcolor("black")
pen.begin_fill()
pen.circle(10)
pen.end_fill()
# 画乌龟的身体
pen.penup()
pen.goto(-150, -50)
pen.pendown()
pen.fillcolor("green")
pen.begin_fill()
pen.circle(150)
pen.end_fill()
# 画乌龟的四肢
pen.penup()
pen.goto(-100, -150)
pen.pendown()
pen.fillcolor("green")
pen.begin_fill()
pen.circle(50)
pen.end_fill()
pen.penup()
pen.goto(100, -150)
pen.pendown()
pen.fillcolor("green")
pen.begin_fill()
pen.circle(50)
pen.end_fill()
pen.penup()
pen.goto(-200, -150)
pen.pendown()
pen.fillcolor("green")
pen.begin_fill()
pen.circle(50)
pen.end_fill()
pen.penup()
pen.goto(200, -150)
pen.pendown()
pen.fillcolor("green")
pen.begin_fill()
pen.circle(50)
pen.end_fill()
# 隐藏画笔
pen.hideturtle()
# 显示画布
canvas.mainloop()
```
希望这个代码能够帮助到你!
阅读全文