用turtle画一幅海底世界
时间: 2023-07-18 18:33:51 浏览: 199
好的,让我来为您展示一下用turtle画一幅海底世界的代码:
```python
import turtle
# 设置画笔和画布
pen = turtle.Turtle()
pen.speed(0)
pen.color('white')
pen.getscreen().bgcolor('blue')
# 画海底
pen.penup()
pen.goto(-300, -200)
pen.pendown()
pen.begin_fill()
pen.goto(300, -200)
pen.goto(300, 0)
pen.goto(-300, 0)
pen.goto(-300, -200)
pen.end_fill()
# 画海底草
pen.penup()
pen.goto(-250, -190)
pen.pendown()
pen.color('green')
pen.begin_fill()
for i in range(2):
pen.forward(50)
pen.right(90)
pen.forward(100)
pen.right(90)
pen.end_fill()
pen.penup()
pen.goto(-150, -190)
pen.pendown()
pen.color('green')
pen.begin_fill()
for i in range(2):
pen.forward(70)
pen.right(90)
pen.forward(120)
pen.right(90)
pen.end_fill()
pen.penup()
pen.goto(50, -190)
pen.pendown()
pen.color('green')
pen.begin_fill()
for i in range(2):
pen.forward(60)
pen.right(90)
pen.forward(90)
pen.right(90)
pen.end_fill()
# 画海底动物
pen.penup()
pen.goto(-200, -50)
pen.pendown()
pen.color('black')
pen.fillcolor('orange')
pen.begin_fill()
pen.circle(50)
pen.end_fill()
pen.penup()
pen.goto(100, -50)
pen.pendown()
pen.color('black')
pen.fillcolor('yellow')
pen.begin_fill()
pen.circle(50)
pen.end_fill()
# 画海星
pen.penup()
pen.goto(-100, -100)
pen.pendown()
pen.color('black')
pen.fillcolor('purple')
pen.begin_fill()
for i in range(5):
pen.forward(50)
pen.right(144)
pen.end_fill()
# 完成
turtle.done()
```
运行代码后,您就可以看到一幅色彩缤纷的海底世界啦!
阅读全文