使用python绘制五星红旗
时间: 2024-01-10 22:15:49 浏览: 213
好的,您可以使用Python中的turtle库进行绘制。以下是绘制五星红旗的代码:
```
import turtle
# 设置画布
turtle.setup(width=800, height=533)
turtle.title('绘制五星红旗')
# 绘制红色背景
turtle.penup()
turtle.goto(-400, 266.5)
turtle.pendown()
turtle.begin_fill()
turtle.color('red')
turtle.forward(800)
turtle.right(90)
turtle.forward(533)
turtle.right(90)
turtle.forward(800)
turtle.right(90)
turtle.forward(533)
turtle.end_fill()
# 绘制大星星
turtle.penup()
turtle.goto(-200, 157.5)
turtle.setheading(0)
turtle.pendown()
turtle.begin_fill()
turtle.color('yellow')
for _ in range(5):
turtle.forward(50)
turtle.right(144)
turtle.end_fill()
# 绘制小星星
pos = [(65, 180), (75, 157.5), (75, 135), (65, 112.5), (40, 112.5),
(49, 135), (40, 157.5)]
turtle.penup()
turtle.color('yellow')
for x, y in pos:
turtle.goto(x - 400, y - 266.5)
turtle.setheading(0)
turtle.pendown()
turtle.begin_fill()
for _ in range(5):
turtle.forward(10)
turtle.right(144)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 等待窗口关闭
turtle.done()
```
希望这可以帮助您!
阅读全文