python海龟绘图画精美龙舟
时间: 2023-06-21 12:07:51 浏览: 172
下面是一个简单的示例代码,使用Python的turtle库绘制一个精美的龙舟:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(800, 600)
turtle.bgcolor('cyan')
# 绘制龙船的船身
turtle.penup()
turtle.goto(-200, 0)
turtle.pendown()
turtle.pensize(5)
turtle.color('brown')
turtle.begin_fill()
turtle.forward(400)
turtle.right(90)
turtle.circle(50, 180)
turtle.right(90)
turtle.forward(400)
turtle.end_fill()
# 绘制龙船的桨
turtle.penup()
turtle.goto(-100, 100)
turtle.pendown()
turtle.pensize(3)
turtle.color('black')
turtle.begin_fill()
turtle.left(45)
turtle.forward(100)
turtle.right(90)
turtle.forward(10)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(10)
turtle.end_fill()
# 绘制龙船的旗帜
turtle.penup()
turtle.goto(200, 100)
turtle.pendown()
turtle.pensize(3)
turtle.color('red')
turtle.begin_fill()
turtle.forward(50)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(50)
turtle.end_fill()
# 绘制龙船的龙头
turtle.penup()
turtle.goto(200, 0)
turtle.pendown()
turtle.pensize(5)
turtle.color('black')
turtle.begin_fill()
turtle.circle(50)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.circle(50, 180)
turtle.right(90)
turtle.forward(50)
turtle.end_fill()
# 隐藏海龟
turtle.hideturtle()
# 显示绘制结果
turtle.done()
```
运行以上代码,将会得到一个绘制出来的精美龙舟。你也可以根据需要,进行进一步的修改和优化。
阅读全文