用python的turtle画龙舟
时间: 2023-07-01 17:28:33 浏览: 257
好的,让我来为您展示用 Python 的 turtle 库画龙舟的过程:
首先,我们需要导入 turtle 库:
```python
import turtle
```
然后,我们需要定义一个函数,用于画龙舟:
```python
def draw_dragonboat():
# 设置画笔的颜色和大小
turtle.pensize(5)
turtle.pencolor('red')
# 画船底
turtle.penup()
turtle.goto(-200, 0)
turtle.pendown()
turtle.begin_fill()
turtle.color('orange')
turtle.forward(400)
turtle.left(90)
turtle.circle(50, 180)
turtle.left(90)
turtle.forward(400)
turtle.end_fill()
# 画船头
turtle.penup()
turtle.goto(200, 0)
turtle.pendown()
turtle.begin_fill()
turtle.color('orange')
turtle.left(180)
turtle.circle(-50, 180)
turtle.left(90)
turtle.forward(80)
turtle.left(90)
turtle.circle(-30, 180)
turtle.left(90)
turtle.forward(80)
turtle.end_fill()
# 画桨
turtle.penup()
turtle.goto(-150, 100)
turtle.pendown()
turtle.begin_fill()
turtle.color('black')
turtle.right(45)
turtle.forward(100)
turtle.circle(-10, 180)
turtle.forward(100)
turtle.end_fill()
turtle.penup()
turtle.goto(150, 100)
turtle.pendown()
turtle.begin_fill()
turtle.color('black')
turtle.left(90)
turtle.forward(100)
turtle.circle(10, 180)
turtle.forward(100)
turtle.end_fill()
# 画龙头
turtle.penup()
turtle.goto(0, 150)
turtle.pendown()
turtle.begin_fill()
turtle.color('yellow')
turtle.circle(30)
turtle.end_fill()
turtle.penup()
turtle.goto(0, 170)
turtle.pendown()
turtle.begin_fill()
turtle.color('red')
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(0, 180)
turtle.pendown()
turtle.begin_fill()
turtle.color('yellow')
turtle.circle(10)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 等待用户关闭窗口
turtle.done()
```
最后,在主函数中调用这个函数即可:
```python
if __name__ == '__main__':
draw_dragonboat()
```
这样,就可以在窗口中画出一个漂亮的龙舟了。
阅读全文