用python turtle 画一个小动物
时间: 2023-11-06 17:06:06 浏览: 169
python turtle实现小人发射爱心
5星 · 资源好评率100%
好的,我可以教你如何画一个小乌龟🐢。
首先,我们需要导入 turtle 库:
```python
import turtle
```
然后,我们可以创建一个画布和一个画笔:
```python
win = turtle.Screen()
pen = turtle.Turtle()
```
接下来,我们可以画出乌龟的身体和头部:
```python
pen.pensize(4)
pen.penup()
pen.goto(0, -100)
pen.pendown()
pen.circle(100)
pen.penup()
pen.goto(0, 0)
pen.pendown()
pen.circle(50)
```
然后是乌龟的四肢:
```python
pen.penup()
pen.goto(-70, -70)
pen.pendown()
pen.right(45)
pen.forward(70)
pen.penup()
pen.goto(70, -70)
pen.pendown()
pen.left(90)
pen.forward(70)
pen.penup()
pen.goto(-70, -130)
pen.pendown()
pen.right(90)
pen.forward(70)
pen.penup()
pen.goto(70, -130)
pen.pendown()
pen.left(90)
pen.forward(70)
```
最后是乌龟的眼睛和嘴巴:
```python
pen.penup()
pen.goto(-30, 20)
pen.pendown()
pen.dot(30)
pen.penup()
pen.goto(30, 20)
pen.pendown()
pen.dot(30)
pen.penup()
pen.goto(0, 0)
pen.pendown()
pen.right(90)
pen.forward(50)
pen.write("Hello, I'm a turtle!", align="center", font=("Arial", 16, "normal"))
```
完整代码如下:
```python
import turtle
win = turtle.Screen()
pen = turtle.Turtle()
pen.pensize(4)
pen.penup()
pen.goto(0, -100)
pen.pendown()
pen.circle(100)
pen.penup()
pen.goto(0, 0)
pen.pendown()
pen.circle(50)
pen.penup()
pen.goto(-70, -70)
pen.pendown()
pen.right(45)
pen.forward(70)
pen.penup()
pen.goto(70, -70)
pen.pendown()
pen.left(90)
pen.forward(70)
pen.penup()
pen.goto(-70, -130)
pen.pendown()
pen.right(90)
pen.forward(70)
pen.penup()
pen.goto(70, -130)
pen.pendown()
pen.left(90)
pen.forward(70)
pen.penup()
pen.goto(-30, 20)
pen.pendown()
pen.dot(30)
pen.penup()
pen.goto(30, 20)
pen.pendown()
pen.dot(30)
pen.penup()
pen.goto(0, 0)
pen.pendown()
pen.right(90)
pen.forward(50)
pen.write("Hello, I'm a turtle!", align="center", font=("Arial", 16, "normal"))
turtle.done()
```
运行上述代码,你将会看到一个可爱的小乌龟在画布上出现了!
阅读全文