最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python 繪制國旗的示例

 更新時間:2020年09月27日 08:31:32   作者:Python技術  
這篇文章主要介紹了python 繪制國旗的示例,幫助大家利用python繪制,處理圖像,感興趣的朋友可以了解下

國旗是一個國家的象征,它可以反映一個國家的特色和傳統(tǒng),國旗起源于近代的歐洲,是一個國家主權意識不斷增強后的必然產物,本文我們使用 Python 來畫幾面國旗,使用的 Python 庫是大家比較熟悉的 turtle。

五星紅旗

五星紅旗是中華人民共和國的國旗,它是由四顆小的黃五角星環(huá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()

實現效果如下:

青天白日旗

青天白日旗是民國時期的國旗,旗面作藍色以示青天,旗中置一射出叉光的白日圖案,實現代碼如下:

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)

實現效果如下:

紅底白十字旗

紅底白十字旗是瑞士的國旗,與其他國家有點不同,瑞士的國旗形狀是正方形的,代表了該國堅守中立的政策,實現代碼如下:

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()

實現效果如下:

星條旗

星條旗是美國的國旗,由兩部分組成,旗的左上方藍底上排列著 50 顆白色的星,其余部分是 13 道紅白相間的條子,實現代碼如下:

# 畫條紋
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 繪制了幾面國旗,有興趣的可以嘗試繪制一下其他國家的國旗。

示例代碼:https://github.com/JustDoPython/python-examples/tree/master/yeke/py-flag

以上就是python 繪制國旗的示例的詳細內容,更多關于python 繪制國旗的資料請關注腳本之家其它相關文章!

相關文章

  • 基于PyQt5完成pdf轉word功能

    基于PyQt5完成pdf轉word功能

    本文介紹的pdf轉word功能還有一些待完善地方,例如可增加預覽功能,實現每頁預覽,當然我們可以在后續(xù)階段逐漸完善,對基于PyQt5完成的pdf轉word功能感興趣的朋友一起看看吧
    2022-06-06
  • 關于Python中兩個不同shape的數組間運算規(guī)則

    關于Python中兩個不同shape的數組間運算規(guī)則

    這篇文章主要介紹了關于Python中兩個不同shape的數組間運算規(guī)則,眾所周知,相同?shape?的兩個數組間運算是指兩個數組的對應元素相加,我們經常會碰到一些不同?shape?的數組間運算,需要的朋友可以參考下
    2023-08-08
  • Python2.7下安裝Scrapy框架步驟教程

    Python2.7下安裝Scrapy框架步驟教程

    本篇文章主要介紹了Python2.7下安裝Scrapy框架步驟教程,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-12-12
  • python利用遞歸方法實現求集合的冪集

    python利用遞歸方法實現求集合的冪集

    這篇文章主要給大家介紹了關于python利用遞歸方法實現求集合的冪集的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-09-09
  • Python處理字符串之isspace()方法的使用

    Python處理字符串之isspace()方法的使用

    這篇文章主要介紹了Python處理字符串之isspace()方法的使用,是Python入門中的基礎知識,需要的朋友可以參考下
    2015-05-05
  • 簡單介紹Python中的filter和lambda函數的使用

    簡單介紹Python中的filter和lambda函數的使用

    這篇文章主要簡單介紹了Python中的filter和lambda函數的使用,是Python學習中的基礎,同時lambda匿名函數的使用也是經常被用來對比各種編程語的重要特性,言需要的朋友可以參考下
    2015-04-04
  • Python產生一個數值范圍內的不重復的隨機數的實現方法

    Python產生一個數值范圍內的不重復的隨機數的實現方法

    這篇文章主要介紹了Python產生一個數值范圍內的不重復的隨機數的實現方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-08-08
  • python文件轉為exe文件的方法及用法詳解

    python文件轉為exe文件的方法及用法詳解

    py2exe是一個將python腳本轉換成windows上的可獨立執(zhí)行的可執(zhí)行程序(*.exe)的工具,這樣,你就可以不用裝python而在windows系統(tǒng)上運行這個可執(zhí)行程序。本文重點給大家介紹python文件轉為exe文件的方法,感興趣的朋友跟隨小編一起看看吧
    2019-07-07
  • Python使用reportlab模塊生成PDF格式的文檔

    Python使用reportlab模塊生成PDF格式的文檔

    今天小編就為大家分享一篇關于Python使用reportlab模塊生成PDF格式的文檔,小編覺得內容挺不錯的,現在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2019-03-03
  • 使用python求斐波那契數列中第n個數的值示例代碼

    使用python求斐波那契數列中第n個數的值示例代碼

    這篇文章主要給大家介紹了關于使用python求斐波那契數列中第n個數的值的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者使用python具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧
    2020-07-07

最新評論

荥阳市| 临西县| 武威市| 华宁县| 朔州市| 望江县| 宜良县| 南华县| 广南县| 罗甸县| 广安市| 修文县| 东明县| 霍山县| 永年县| 大安市| 台北市| 揭阳市| 瑞金市| 山阴县| 共和县| 常德市| 白城市| 得荣县| 昌邑市| 和硕县| 黄冈市| 屏东县| 南召县| 新晃| 浠水县| 辽源市| 金沙县| 东海县| 南宁市| 保德县| 利津县| 大理市| 句容市| 新乡县| 砚山县|