科摩罗国旗是由四个不同颜色的竖条组成,每个竖条内填充着不同的图案。Python画科摩罗国旗需要使用turtle库进行绘制,代码如下:
import turtle # 设置窗口大小 turtle.setup(600, 400) # 绘制绿色竖条 turtle.penup() turtle.goto(-150, 0) turtle.pendown() turtle.color("green") turtle.begin_fill() turtle.fd(300) turtle.right(90) turtle.fd(100) turtle.right(90) turtle.fd(300) turtle.right(90) turtle.fd(100) turtle.end_fill() # 绘制黄色竖条 turtle.penup() turtle.goto(-50, 0) turtle.pendown() turtle.color("yellow") turtle.begin_fill() turtle.fd(100) turtle.right(90) turtle.fd(100) turtle.right(90) turtle.fd(100) turtle.right(90) turtle.fd(100) turtle.end_fill() # 绘制红色竖条 turtle.penup() turtle.goto(50, 0) turtle.pendown() turtle.color("red") turtle.begin_fill() turtle.fd(100) turtle.right(90) turtle.fd(100) turtle.right(90) turtle.fd(100) turtle.right(90) turtle.fd(100) turtle.end_fill() # 绘制星形 turtle.penup() turtle.goto(-25, 25) turtle.pendown() turtle.color("white") turtle.begin_fill() for i in range(5): turtle.fd(50) turtle.right(144) turtle.end_fill() turtle.hideturtle() turtle.done()
运行上述代码即可绘制出科摩罗国旗。