Python画五星红旗
时间: 2023-11-05 17:53:49 浏览: 314
python 实现五星红旗源码
以下是用Python绘制五星红旗的示例代码:
```python
import turtle
# 设置窗口大小和背景颜色
turtle.setup(800, 500)
turtle.bgcolor('#DE2910')
# 画大矩形
turtle.penup()
turtle.goto(-300, 200)
turtle.begin_fill()
turtle.color('#FDEE00')
turtle.pendown()
turtle.forward(600)
turtle.right(90)
turtle.forward(400)
turtle.right(90)
turtle.forward(600)
turtle.right(90)
turtle.forward(400)
turtle.end_fill()
# 画小矩形
turtle.penup()
turtle.goto(-260, 160)
turtle.begin_fill()
turtle.color('#DE2910')
turtle.pendown()
turtle.forward(160)
turtle.right(90)
turtle.forward(80)
turtle.right(90)
turtle.forward(160)
turtle.right(90)
turtle.forward(80)
turtle.end_fill()
# 画大星星
turtle.penup()
turtle.goto(-200, 220)
turtle.begin_fill()
turtle.color('#FDEE00')
turtle.pendown()
for i in range(5):
turtle.forward(80)
turtle.right(144)
turtle.end_fill()
# 画小星星1
turtle.penup()
turtle.goto(-120, 270)
turtle.begin_fill()
turtle.color('#FDEE00')
turtle.pendown()
for i in range(5):
turtle.forward(32)
turtle.right(144)
turtle.end_fill()
# 画小星星2
turtle.penup()
turtle.goto(-100, 200)
turtle.begin_fill()
turtle.color('#FDEE00')
turtle.pendown()
for i in range(5):
turtle.forward(32)
turtle.right(144)
turtle.end_fill()
# 画小星星3
turtle.penup()
turtle.goto(-120, 130)
turtle.begin_fill()
turtle.color('#FDEE00')
turtle.pendown()
for i in range(5):
turtle.forward(32)
turtle.right(144)
turtle.end_fill()
# 画小星星4
turtle.penup()
turtle.goto(-200, 90)
turtle.begin_fill()
turtle.color('#FDEE00')
turtle.pendown()
for i in range(5):
turtle.forward(32)
turtle.right(144)
turtle.end_fill()
# 隐藏海龟
turtle.hideturtle()
# 显示绘图窗口
turtle.done()
```
运行上述代码,即可在绘图窗口中看到绘制出来的五星红旗。
阅读全文