python升国旗代码
时间: 2023-10-28 14:01:38 浏览: 410
以下是 Python 实现的升国旗代码:
```python
import turtle
def draw_rectangle(x, y, width, height, color):
turtle.up()
turtle.goto(x, y)
turtle.fillcolor(color)
turtle.begin_fill()
for i in range(2):
turtle.forward(width)
turtle.right(90)
turtle.forward(height)
turtle.right(90)
turtle.end_fill()
def draw_star(x, y, radius, color):
turtle.up()
turtle.goto(x, y)
turtle.setheading(0)
turtle.right(72)
turtle.fillcolor(color)
turtle.begin_fill()
turtle.down()
for i in range(5):
turtle.forward(radius)
turtle.right(144)
turtle.forward(radius)
turtle.right(72 - 144)
turtle.end_fill()
def draw_china_flag(x, y):
turtle.speed(10)
turtle.hideturtle()
turtle.bgcolor('red')
# 画大矩形
big_width = 640
big_height = 400
draw_rectangle(x, y, big_width, big_height, 'red')
# 画小矩形
small_width = 320
small_height = 200
draw_rectangle(x, y+140, small_width, small_height, 'yellow')
# 画星星
star_x = x + 40
star_y = y + 320
radius = 20
draw_star(star_x, star_y, radius, 'yellow')
# 画四颗小星星
gap = 60
for i in range(4):
x = star_x + gap * (i+1)
y = star_y - gap
draw_star(x, y, radius, 'yellow')
if __name__ == '__main__':
draw_china_flag(-320, -200)
turtle.mainloop()
```
运行代码后,会看到窗口里绘制了一面中国国旗。
阅读全文