用python语言画一只乌龟
时间: 2023-10-21 11:03:57 浏览: 79
python画图-使用Python+turtle实现画花.zip
可以使用Python的turtle库来画一只乌龟。
以下是一份简单的示例代码:
```python
import turtle
# 创建画布和画笔
window = turtle.Screen()
turtle_pen = turtle.Turtle()
# 画乌龟的头
turtle_pen.penup()
turtle_pen.goto(0, 100)
turtle_pen.pendown()
turtle_pen.circle(50)
# 画乌龟的身体
turtle_pen.penup()
turtle_pen.goto(0, 70)
turtle_pen.pendown()
turtle_pen.circle(80)
# 画乌龟的四肢
turtle_pen.penup()
turtle_pen.goto(40, 40)
turtle_pen.pendown()
turtle_pen.circle(20)
turtle_pen.penup()
turtle_pen.goto(-40, 40)
turtle_pen.pendown()
turtle_pen.circle(20)
turtle_pen.penup()
turtle_pen.goto(60, -10)
turtle_pen.pendown()
turtle_pen.circle(20)
turtle_pen.penup()
turtle_pen.goto(-60, -10)
turtle_pen.pendown()
turtle_pen.circle(20)
# 画乌龟的眼睛
turtle_pen.penup()
turtle_pen.goto(15, 120)
turtle_pen.pendown()
turtle_pen.dot(20)
turtle_pen.penup()
turtle_pen.goto(-15, 120)
turtle_pen.pendown()
turtle_pen.dot(20)
# 画乌龟的嘴巴
turtle_pen.penup()
turtle_pen.goto(0, 90)
turtle_pen.pendown()
turtle_pen.circle(20, 180)
# 隐藏画笔
turtle_pen.hideturtle()
# 关闭画布
window.exitonclick()
```
运行以上代码,会在窗口中生成一只乌龟的图像。你可以根据需要进行修改和调整,让乌龟更加逼真。
阅读全文