python画美国国旗,小白画法

廉价感情. 提交于 2020-02-24 07:12:28
import turtle as t
t.speed(9)        #设置速度
long=741          #国旗长         按照美国国旗比例设置长宽
wide=390          #国旗宽
wide1=wide/13     #每格宽度
t.setup(long,wide)                   #按照国旗比例设置19:10的画布
t.up()
t.goto(-long/2,wide/2)              #移动到左上顶点

def Rectangle():                 #定义一个循环画长方形函数
    t.color("red")
    a = 165
    for i in range(7):
        t.down()
        t.begin_fill()
        t.forward(long)
        t.goto(long/2,a)
        t.back(long)
        t.end_fill()
        t.up()
        t.goto(-long/2,a-30)
        a-=60
Rectangle()

def BlueState():                 #定义蓝色部分
    t.color("blue")
    t.up()
    t.goto(-long/2,wide/2)
    t.begin_fill()
    t.forward(long/2)
    t.goto(0,-15)
    t.back(long/2)
    t.end_fill()
BlueState()

def Star(x,y):                 #定义画星星函数
    t.color("white")
    t.up()
    t.goto(x,y)
    t.begin_fill()
    for i in range(5):
        t.forward(15)
        t.right(144)
    t.end_fill()

sterx = -344                    #6*5星星
for i in range(6):
    stery = 178
    for j in range(5):
        Star(sterx,stery)
        stery -= 42
    sterx+=60
sterm=-314                      #5*4星星
for i in range(5):
    stern=157
    for j in range(4):
        Star(sterm,stern)
        stern-=42
    sterm+=60
t.hideturtle()                 #隐藏箭头
t.done()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!