p ython用turtle画小动物
时间: 2024-05-13 10:19:20 浏览: 105
好的,我们可以使用 Python 自带的 Turtle 模块来画小动物,以下是一些示例代码:
1. 画一只乌龟:
```python
import turtle
# 创建画布和画笔
canvas = turtle.Screen()
pen = turtle.Turtle()
# 画乌龟的头部
pen.penup()
pen.goto(0, 100)
pen.pendown()
pen.circle(50)
# 画乌龟的身体
pen.penup()
pen.goto(0, 0)
pen.pendown()
pen.circle(100)
# 画乌龟的四肢
pen.penup()
pen.goto(-70, -50)
pen.pendown()
pen.circle(30)
pen.penup()
pen.goto(70, -50)
pen.pendown()
pen.circle(30)
pen.penup()
pen.goto(-100, -120)
pen.pendown()
pen.circle(30)
pen.penup()
pen.goto(100, -120)
pen.pendown()
pen.circle(30)
# 完成画图,关闭窗口
canvas.exitonclick()
```
2. 画一只兔子:
```python
import turtle
# 创建画布和画笔
canvas = turtle.Screen()
pen = turtle.Turtle()
# 画兔子的头部
pen.penup()
pen.goto(0, 100)
pen.pendown()
pen.begin_fill()
pen.color("pink")
pen.circle(50)
pen.end_fill()
# 画兔子的耳朵
pen.penup()
pen.goto(0, 160)
pen.pendown()
pen.begin_fill()
pen.color("pink")
pen.right(45)
pen.forward(70)
pen.left(90)
pen.forward(70)
pen.left(90)
pen.forward(70)
pen.end_fill()
pen.penup()
pen.goto(0, 160)
pen.pendown()
pen.begin_fill()
pen.color("pink")
pen.right(135)
pen.forward(70)
pen.left(90)
pen.forward(70)
pen.left(90)
pen.forward(70)
pen.end_fill()
# 画兔子的身体
pen.penup()
pen.goto(0, 0)
pen.pendown()
pen.begin_fill()
pen.color("white")
pen.circle(100)
pen.end_fill()
# 画兔子的四肢
pen.penup()
pen.goto(-70, -50)
pen.pendown()
pen.begin_fill()
pen.color("white")
pen.circle(30)
pen.end_fill()
pen.penup()
pen.goto(70, -50)
pen.pendown()
pen.begin_fill()
pen.color("white")
pen.circle(30)
pen.end_fill()
pen.penup()
pen.goto(-100, -120)
pen.pendown()
pen.begin_fill()
pen.color("white")
pen.circle(30)
pen.end_fill()
pen.penup()
pen.goto(100, -120)
pen.pendown()
pen.begin_fill()
pen.color("white")
pen.circle(30)
pen.end_fill()
# 画兔子的眼睛和嘴巴
pen.penup()
pen.goto(-20, 180)
pen.pendown()
pen.begin_fill()
pen.color("black")
pen.circle(10)
pen.end_fill()
pen.penup()
pen.goto(20, 180)
pen.pendown()
pen.begin_fill()
pen.color("black")
pen.circle(10)
pen.end_fill()
pen.penup()
pen.goto(0, 140)
pen.pendown()
pen.right(90)
pen.forward(20)
pen.left(90)
pen.forward(40)
# 完成画图,关闭窗口
canvas.exitonclick()
```
你可以根据自己的喜好和创意,自由发挥画出更多有趣的小动物。
阅读全文