Python画国旗

前言

今天,我们来用turtle库来绘制国旗

一、美国国旗

国旗的形状是长方形;国旗的长宽之比为19:10,美国国旗由红、白、蓝三色组成;画面格局由两部分组成,旗的左上方蓝底上排列着50颗白色的星,6颗一排与5颗一排相间排列,共排9行;旗的其余部分是13道红白相间的条子,有7道红色横条以及6道白色横条 。

python 复制代码
import  turtle    
t = turtle.Pen()
b = turtle.Pen()   
t.speed(800)      
def ct(c):    
    t.color(c)     
    t.begin_fill()
    for i in range(2):
        t.forward(247)  
        t.right(90)
        t.forward(10)
        t.right(90)
    t.end_fill()
for i in range(14):  
    if i%2==1:   
        c ='white'
    else:
        c ='red'
    ct(c)
    t.right(90)
    t.forward(10)
    t.left(90)
t.up()     
t.home()
t.down()
for j in range(4):   
    t.color('blue')    
    t.begin_fill()
    t.forward(120)
    t.right(90)
    t.forward(70)
    t.right(90)
    t.end_fill()
def wjx():       
    b.color('white')
    b.begin_fill()
    for g in range(5):
        b.forward(6)
        b.left(144)
    b.end_fill()
def wjx6():     
    for l in range(6):
        b.up()
        b.forward(3)
        b.down()
        wjx()
        b.up()
        b.forward(18)
        b.down()
def wjx5():     
    for l in range(5):
        b.up()
        b.forward(10)
        b.down()
        wjx()
        b.up()
        b.forward(13)
        b.down()
b.right(90)    
b.forward(7)      
b.left(90)
for u in range(9):      
    if u%2 == 0:        
        wjx6()
    else:
        wjx5()     
    b.up()     
    b.home()
    b.right(90)
    b.forward((u+2)*7)
    b.left(90)
    b.down()
turtle.done()   

二、奥兰群岛旗

奥兰群岛又称阿赫韦南马群岛(Ahvenanmaa),是芬兰唯一的一个自治省,位于芬兰的西南沿海,由6500个小岛组成,岛上居民2.5万人,大多以瑞典语为母语。奥兰群岛的首府是玛丽港(Mairenhamn)。

python 复制代码
import turtle
 
width = 900
height = 600
 
turtle.screensize(width,height,"#0053a5")
turtle.setup(width,height)
t = turtle.Turtle()
t.speed(10)
 
t.pencolor("#ffce00")
t.fillcolor("#ffce00")
t.hideturtle()
 
t.penup()
t.goto(0,-170/3)
t.pendown()
t.begin_fill()
t.forward(width / 2)
t.left(90)
t.forward(170)
t.left(90)
t.forward(width)
t.left(90)
t.forward(170)
t.end_fill()
 
t.penup()
t.goto(0,height/2)
t.pendown()
t.begin_fill()
t.forward(height)
t.right(90)
t.forward(170)
t.right(90)
t.forward(height)
t.end_fill()
 
t.pencolor("#d21034")
t.fillcolor("#d21034")
 
t.penup()
t.goto(-170 / 3,height/2)
t.pendown()
t.begin_fill()
t.left(90)
t.forward(170/3)
t.left(90)
t.forward(height)
t.left(90)
t.forward(170/3)
t.end_fill()
 
t.penup()
t.goto(-width/2,0)
t.pendown()
t.begin_fill()
t.forward(width)
t.left(90)
t.forward(170/3)
t.left(90)
t.forward(width)
t.left(90)
t.end_fill()
 
turtle.mainloop()
相关推荐
z落落4 分钟前
C#WinForm 窗体切换与窗体传值(登录跳转案例)+WinForm 窗体传值(从上往下传、从下往上传)
开发语言·windows·c#
CTA量化套保12 分钟前
期货量化程序 time.sleep 卡死:天勤单线程与 deadline 替代
python·区块链
allway216 分钟前
How to Echo Multiline to a File in Bash [3 Methods]
开发语言·chrome·bash
weixin_4624462317 分钟前
手把手教你用 Bash 脚本自动更新 /etc/hosts —— 自动绑定网卡 IP 与节点名
开发语言·tcp/ip·bash
一个梦醒了19 分钟前
安装git bash选项推荐
开发语言·git·bash
GIS数据转换器32 分钟前
城市排水生命线安全运行监测平台深度解析
java·运维·人工智能·python·安全·数据挖掘·无人机
ct97844 分钟前
React 状态管理方案深度对比
开发语言·前端·react
贤哥哥yyds1 小时前
GBK转UTF\-8编码自动转换工具 使用文档
python
数量技术宅1 小时前
2026量化前沿:从Reddit热帖到Python实战,如何用赫斯特指数(Hurst)狙击虚假突破?
开发语言·python
华如锦1 小时前
面了很多 Java转AI Agent方向,一些面试题总结
java·开发语言·人工智能·python·ai