用turtle画兔子并且有for循环
时间: 2024-05-10 08:19:47 浏览: 59
用turtle画小兔子.py
好的,我可以帮您回答这个问题。以下是用 Python turtle 模块画兔子的代码:
```python
import turtle
# 设置画布大小
turtle.setup(500, 500)
# 定义兔子的形状
turtle.penup()
turtle.goto(0, -80)
turtle.pendown()
turtle.color('brown', 'white')
turtle.begin_fill()
turtle.circle(50)
turtle.end_fill()
# 画兔子的眼睛
turtle.penup()
turtle.goto(-20, 10)
turtle.pendown()
turtle.color('black')
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
turtle.penup()
turtle.goto(20, 10)
turtle.pendown()
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
# 画兔子的嘴巴
turtle.penup()
turtle.goto(-25, -10)
turtle.pendown()
turtle.color('brown')
turtle.setheading(270)
turtle.circle(25, 180)
# 画兔子的耳朵
turtle.penup()
turtle.goto(-20, 60)
turtle.pendown()
turtle.color('brown', 'white')
turtle.begin_fill()
for i in range(3):
turtle.forward(40)
turtle.left(120)
turtle.end_fill()
turtle.penup()
turtle.goto(20, 60)
turtle.pendown()
turtle.color('brown', 'white')
turtle.begin_fill()
for i in range(3):
turtle.forward(40)
turtle.right(120)
turtle.end_fill()
# 画兔子的胡须
turtle.penup()
turtle.goto(-30, 20)
turtle.pendown()
turtle.color('black')
for i in range(5):
turtle.forward(15)
turtle.right(10)
turtle.penup()
turtle.goto(-30, 0)
turtle.pendown()
turtle.color('black')
for i in range(5):
turtle.forward(15)
turtle.right(10)
turtle.penup()
turtle.goto(-30, -20)
turtle.pendown()
turtle.color('black')
for i in range(5):
turtle.forward(15)
turtle.right(10)
turtle.hideturtle()
turtle.done()
```
代码中使用 for 循环来画兔子的耳朵和胡须,希望可以帮到您!
阅读全文