Python海龟绘图国旗
时间: 2023-12-14 11:32:47 浏览: 116
以下是Python海龟绘图国旗的代码示例:
```python
import turtle
# 设置画笔大小和速度
turtle.pensize(5)
turtle.speed(10)
# 绘制矩形
turtle.penup()
turtle.goto(-300, 200)
turtle.pendown()
turtle.color('red')
turtle.begin_fill()
for i in range(2):
turtle.forward(600)
turtle.right(90)
turtle.forward(400)
turtle.right(90)
turtle.end_fill()
# 绘制大五角星
turtle.penup()
turtle.goto(-200, 120)
turtle.pendown()
turtle.color('yellow')
turtle.begin_fill()
for i in range(5):
turtle.forward(120)
turtle.right(144)
turtle.end_fill()
# 绘制四个小五角星
turtle.penup()
turtle.goto(-90, 170)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(30)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-70, 100)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(30)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-70, 30)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(30)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-90, -40)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(30)
turtle.right(144)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 显示绘图窗口
turtle.done()
```
阅读全文