您好,登錄后才能下訂單哦!
這篇文章主要為大家展示了“怎么用Python畫國(guó)家的國(guó)旗”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“怎么用Python畫國(guó)家的國(guó)旗”這篇文章吧。
五星紅旗是中華人民共和國(guó)的國(guó)旗,它是由四顆小的黃五角星環(huán)繞一顆大的黃五角星組成的,底色為紅色,實(shí)現(xiàn)代碼如下:
turtle.setup(600,400,0,0) turtle.bgcolor("red") turtle.fillcolor("yellow") turtle.color('yellow') turtle.speed(10) # 主星 turtle.begin_fill() turtle.up() turtle.goto(-280,100) turtle.down() for i in range (5): turtle.forward(150) turtle.right(144) turtle.end_fill() # 副星 turtle.begin_fill() turtle.up() turtle.goto(-100,180) turtle.setheading(305) turtle.down() for i in range (5): turtle.forward(50) turtle.left(144) turtle.end_fill() turtle.begin_fill() turtle.up() turtle.goto(-50,110) turtle.setheading(30) turtle.down() for i in range (5): turtle.forward(50) turtle.right(144) turtle.end_fill() turtle.begin_fill() turtle.up() turtle.goto(-40,50) turtle.setheading(5) turtle.down() for i in range (5): turtle.forward(50) turtle.right(144) turtle.end_fill() turtle.begin_fill() turtle.up() turtle.goto(-100,10) turtle.setheading(300) turtle.down() for i in range (5): turtle.forward(50) turtle.left(144) turtle.end_fill() turtle.hideturtle() turtle.done()
青天白日旗是民國(guó)時(shí)期的國(guó)旗,旗面作藍(lán)色以示青天,旗中置一射出叉光的白日?qǐng)D案,實(shí)現(xiàn)代碼如下:
t.colormode(255) rcblue=(4,0,174) rcred=(254,0,0) def ol(r): na = 15 / 180 * math.pi ol=2*r*math.cos(na) ol=int(round(ol)) return ol def loop(r): t.fd(ol(r)) t.right(150) def main0(a,b): t.color(rcred) t.penup() t.goto(-a/2,b/2) t.pendown() t.begin_fill() t.goto(-a/2,-b/2) t.goto(a/2,-b/2) t.goto(a/2,b/2) t.end_fill() t.penup() t.goto(-a/4,b/4) t.pendown() def main1(a1,b1): t.color('gray',rcblue) t.penup() t.right(90) t.fd(b1/2) t.left(90) t.pendown() t.begin_fill() t.fd(a1/2) t.left(90) t.fd(b1) t.left(90) t.fd(a1) t.left(90) t.fd(b1) t.left(90) t.fd(a1/2) t.end_fill() t.penup() t.goto(-a/4,b/4) t.seth(0) t.pendown() def main2(r): t.pensize = 20 t.color('white', 'white') t.penup() t.fd(r) t.right(180 - 30 / 2) t.pendown() t.begin_fill() for i in range(12): loop(r) t.end_fill() t.penup() t.goto(-a/4,b/4) t.seth(0) t.pendown() def main3(r1,r2): t.color(rcblue, rcblue) t.begin_fill() t.up() t.right(90) t.fd(r1) t.left(90) t.pd() t.circle(r1) t.end_fill() t.penup() t.goto(-a/4,b/4) t.pendown() t.color('white', 'white') t.begin_fill() t.pu() t.right(90) t.fd(r2) t.left(90) t.pd() t.circle(r2) t.end_fill() t.penup() t.goto(-a/4,b/4) t.seth(0) t.pendown() def main(a,b): a1 = a / 2 b1 = b / 2 r = a1 / 4 r2 = a1 / 8 r1 = b1 * 17 / 80 main0(a,b) main1(a1,b1) main2(r) main3(r1,r2) a=1020 b=680 t.setup(1100,700,100,0)
紅底白十字旗是瑞士的國(guó)旗,與其他國(guó)家有點(diǎn)不同,瑞士的國(guó)旗形狀是正方形的,代表了該國(guó)堅(jiān)守中立的政策,實(shí)現(xiàn)代碼如下:
def draw_crossshaped(aTurtle, width=0, height=0, color=None): aTurtle = turtle.Turtle() aTurtle.hideturtle() aTurtle.penup() aTurtle.goto(30, 50) aTurtle.begin_fill() aTurtle.fillcolor(color) for i in range(4): aTurtle.pendown() aTurtle.fd(width) aTurtle.rt(90) aTurtle.fd(height) aTurtle.rt(90) aTurtle.fd(width) aTurtle.lt(90) aTurtle.end_fill() def draw_RQ(times=20.0): width, height = 26 * times, 26 * times window = turtle.Screen() aTurtle = turtle.Turtle() aTurtle.hideturtle() aTurtle.speed(10) aTurtle.penup() aTurtle.goto(-width / 2, height / 2) aTurtle.pendown() aTurtle.begin_fill() aTurtle.fillcolor('red') aTurtle.fd(width) aTurtle.right(90) aTurtle.fd(height) aTurtle.right(90) aTurtle.fd(width) aTurtle.right(90) aTurtle.fd(height) aTurtle.right(90) aTurtle.end_fill() draw_crossshaped(aTurtle, width=80, height=80, color='white') window.exitonclick()
星條旗是美國(guó)的國(guó)旗,由兩部分組成,旗的左上方藍(lán)底上排列著 50 顆白色的星,其余部分是 13 道紅白相間的條子,實(shí)現(xiàn)代碼如下:
# 畫條紋 def drawSquar(): turtle.color('black', 'red') turtle.begin_fill() for i in range(7): turtle.forward(600) turtle.left(90) turtle.forward(350 / 13) turtle.left(90) turtle.forward(600) turtle.right(90) turtle.forward(350 / 13) turtle.right(90) turtle.end_fill() # 畫左上角的小矩形 def drawSmallsqure(): turtle.color('blue') turtle.begin_fill() turtle.left(90) turtle.forward(350 / 2) turtle.left(90) turtle.forward(300) turtle.left(90) turtle.forward(350 * 7 / 13) turtle.left(90) turtle.forward(300) turtle.end_fill() # 畫左上角的星星 def drawSrarts(): x = -10 y = 0 for k in range(4): x = -15 for i in range(6): turtle.goto(x, y) turtle.color('white') turtle.begin_fill() for j in range(5): turtle.left(144) turtle.forward(20) x -= 50 turtle.end_fill() y += 350 / 13 * 2 x = -10 y = 350 / 13 for i in range(3): x = -35 for j in range(5): turtle.goto(x, y) turtle.color('white') turtle.begin_fill() for k in range(5): turtle.left(144) turtle.forward(20) x -= 50 turtle.end_fill() y += 350 / 13 * 2 turtle.setup(0.8, 0.8, -100, -100) turtle.speed(10) turtle.pu() turtle.forward(300) turtle.left(90) turtle.forward(350 / 2) turtle.left(90) drawSquar() turtle.home() drawSmallsqure() turtle.home() drawSrarts() turtle.hideturtle() turtle.done()
以上是“怎么用Python畫國(guó)家的國(guó)旗”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。