画完五星红旗觉得不过瘾,又画了一面星条旗

美国国旗
以下为代码:
"""
项目:美国国旗
方案:
国旗长宽比:19:10
长度:A = 1.9*B
宽度:B
条纹宽度:宽度的1/13 L = 1/13*B
联邦(蓝色)长度:旗面长度的2/5 C = 2/5*A
联邦(蓝色)宽度:旗面宽度的7/13 D = 7/13*B
联邦范围宽度10等分(1/10*D),长度12等分(1/12*C),在交叉点上画星
星的圆形直径为:0.0616*B
颜色:
标准:RGB
红色:178, 34, 52
蓝色:60,59,110
白色:255,255,255
"""
import turtle as t
import math
# 旗面幅度
k = 500
ch = 1.9 * k
t.speed(0)
t.colormode(255)
flag_red = 178, 34, 52
flag_blue = 60, 59, 110
flag_white = 255, 255, 255
# 旗面幅度
t.screensize(canvwidth=ch, canvheight=k, bg=None)
t.penup()
t.goto(-ch / 2, k / 2)
t.pendown()
t.pencolor(flag_red)
for i in range(2):
t.fd(ch)
t.right(90)
t.fd(k)
t.right(90)
# 画条幅
for i in range(0, 14, 2):
t.penup()
t.goto(-0.5 * ch, 0.5 * k - i * 1 / 13 * k)
t.pendown()
t.pensize(1)
t.pencolor(flag_red)
t.fillcolor(flag_red)
t.begin_fill()
for j in range(2):
t.fd(ch)
t.right(90)
t.fd(1 / 13 * k)
t.right(90)
t.end_fill()
# 画联邦蓝色幅面
t.penup()
t.goto(-ch / 2, k / 2)
t.pendown()
t.pencolor(flag_blue)
t.fillcolor(flag_blue)
t.begin_fill()
for i in range(2):
t.fd(2 / 5 * ch)
t.right(90)
t.fd(7 / 13 * k)
t.right(90)
t.end_fill()
# 五角星所在圆的半径 r=0.0308*k,求五角星前进边长qj
r = 0.0308 * k
qj = 2 * math.cos(math.radians(18)) * r # 一笔贯通长度
qj2 = math.cos(math.radians(54)) * r / math.cos(math.radians(36))
# 一笔到位
# def star(x, y):
# t.setheading(0)
# t.penup()
# t.goto(x, y)
# t.right(198)
# t.fd(r)
# t.right(162)
# t.pencolor(flag_white)
# t.fillcolor(flag_white)
# t.pendown()
# t.begin_fill()
# for i in range(5):
# t.fd(qj)
# t.right(144)
# t.end_fill()
# 两笔折线
def star(x, y):
t.setheading(0)
t.penup()
t.goto(x, y)
t.right(198)
t.fd(r)
t.right(162)
t.pencolor(flag_white)
t.fillcolor(flag_white)
t.pendown()
t.begin_fill()
for i in range(5):
t.fd(qj2)
t.right(-72)
t.fd(qj2)
t.right(144)
t.end_fill()
t.penup()
t.goto(-ch / 2, k / 2)
t.pendown()
for i in range(1, 12, 2):
for j in range(1, 10, 2):
star(-(ch / 2 - i * (2 / 5 * ch) / 12), k / 2 - j * (7 / 13 * k) / 10)
t.penup()
t.goto(-(ch / 2 - 2 * (2 / 5 * ch) / 12), k / 2 - 2 * (7 / 13 * k) / 10)
t.pendown()
for i in range(2, 12, 2):
for j in range(2, 10, 2):
star(-(ch / 2 - i * (2 / 5 * ch) / 12), k / 2 - j * (7 / 13 * k) / 10)
t.hideturtle()
t.done()