怎么用Python画加纳国旗
发布网友
发布时间:2022-04-19 14:54
我来回答
共1个回答
热心网友
时间:2022-04-06 03:41
# python6.6
import turtle
def test():
# 加纳共和国国旗呈长方形,长与宽之比为3∶2。
# 自上而下由红、黄、绿三个平行相等的横长方形组成,*部分中间是一颗黑色五角星。
flag_h = 300
flag_w = 450
star_h = flag_h/3
turtle.pensize(2)
turtle.speed(5)
turtle.hideturtle()
def draw_rectangle(color):
turtle.pencolor(color)
turtle.fillcolor(color)
turtle.pendown()
turtle.begin_fill()
turtle.forward(flag_w)
turtle.right(90)
turtle.forward(star_h)
turtle.right(90)
turtle.forward(flag_w)
turtle.right(90)
turtle.forward(star_h)
turtle.end_fill()
turtle.penup()
turtle.back(star_h)
turtle.right(90)
turtle.penup()
turtle.goto(-flag_w / 2, flag_h / 2)
draw_rectangle("red")
draw_rectangle("yellow")
draw_rectangle("green")
# 五角星
turtle.penup()
turtle.goto(0, star_h/2)
turtle.pencolor("black")
turtle.fillcolor("black")
turtle.right(90-18)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(star_h)
turtle.right(180-36)
turtle.end_fill()
turtle.done()
if __name__ == "__main__":
test()