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()
python画美国国旗,小白画法
于 2020-02-23 12:28:48 首次发布
本文介绍了一个使用Python的turtle库绘制美国国旗的程序。该程序详细展示了如何设置画布大小,使用循环绘制红色条纹,填充蓝色区域,并在左上角放置白色五角星,以精确再现美国国旗的设计。
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
Python3.8
Conda
Python
Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本
1万+

被折叠的 条评论
为什么被折叠?



