python画五星红旗
时间: 2023-06-20 13:07:03 浏览: 103
以下是用 Python 代码画五星红旗的方法:
```python
import turtle
# 设置画布大小
turtle.setup(800, 600)
# 画红色背景
turtle.penup()
turtle.goto(-400, 300)
turtle.pendown()
turtle.color("red")
turtle.begin_fill()
for i in range(2):
turtle.forward(800)
turtle.right(90)
turtle.forward(600)
turtle.right(90)
turtle.end_fill()
# 画大星星
turtle.penup()
turtle.goto(-250, 150)
turtle.pendown()
turtle.color("yellow")
turtle.begin_fill()
for i in range(5):
turtle.forward(100)
turtle.right(144)
turtle.end_fill()
# 画小星星1
turtle.penup()
turtle.goto(-150, 225)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(30)
turtle.right(144)
turtle.end_fill()
# 画小星星2
turtle.penup()
turtle.goto(-120, 150)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(30)
turtle.right(144)
turtle.end_fill()
# 画小星星3
turtle.penup()
turtle.goto(-120, 75)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(30)
turtle.right(144)
turtle.end_fill()
# 画小星星4
turtle.penup()
turtle.goto(-150, 0)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(30)
turtle.right(144)
turtle.end_fill()
# 完成画图
turtle.done()
```
运行代码后,就可以在 Turtle Graphics 窗口中看到画出的五星红旗。
阅读全文