Python画五星红旗
时间: 2023-11-05 20:54:51 浏览: 215
python 实现五星红旗源码
以下是用Python代码画五星红旗的方法:
```python
import turtle
# 设置画布大小
turtle.setup(800, 600)
# 画红色背景
turtle.penup()
turtle.goto(-400, 300)
turtle.pendown()
turtle.begin_fill()
turtle.color("red")
turtle.forward(800)
turtle.right(90)
turtle.forward(600)
turtle.right(90)
turtle.forward(800)
turtle.right(90)
turtle.forward(600)
turtle.end_fill()
# 画大星星
turtle.penup()
turtle.goto(-280, 200)
turtle.pendown()
turtle.begin_fill()
turtle.color("yellow")
for i in range(5):
turtle.forward(100)
turtle.right(144)
turtle.end_fill()
# 画四个小星星
turtle.penup()
turtle.goto(-120, 220)
turtle.pendown()
turtle.begin_fill()
turtle.color("yellow")
for i in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-100, 120)
turtle.pendown()
turtle.begin_fill()
turtle.color("yellow")
for i in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-60, 180)
turtle.pendown()
turtle.begin_fill()
turtle.color("yellow")
for i in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-40, 80)
turtle.pendown()
turtle.begin_fill()
turtle.color("yellow")
for i in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 显示画布
turtle.done()
```
执行以上代码,即可在画布上绘制出五星红旗。如下图所示:
![五星红旗](https://img-blog.csdn.net/20180903172349841?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3BhY2tjYXNl/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/q/80)
阅读全文