科摩羅國(guó)旗是由四個(gè)不同顏色的豎條組成,每個(gè)豎條內(nèi)填充著不同的圖案。Python畫(huà)科摩羅國(guó)旗需要使用turtle庫(kù)進(jìn)行繪制,代碼如下:
import turtle # 設(shè)置窗口大小 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()
運(yùn)行上述代碼即可繪制出科摩羅國(guó)旗。