喜迎国庆,按GB12982-2004标准画的国旗:
如图:
import math
import turtle as t
length = 960
width = length * 2 / 3
square_length = length / 30
t.setup(length, width)
t.speed(0)
t.Screen().bgcolor('black')
t.color('red')
def jump(a, b):
t.up()
t.goto(square_length * a, square_length * b)
t.down()
def five_star(di):
t.left(90 - 18)
t.color('yellow', 'yellow')
t.begin_fill()
for _ in range(5):
t.forward(di * math.cos(math.radians(18)))
t.left(144)
t.end_fill()
t.color('red')
def circle_star(x, y, ex, d=2, head=270):
if ex != 0:
jump(-10, 5)
t.goto(square_length * (x + 1), square_length * y)
jump(x, y)
t.setheading(head)
t.circle(square_length * d / 2)
t.circle(square_length, math.degrees(math.atan(ex)))
five_star(square_length * d)
jump(-15, 0)
t.goto(length / 2, 0)
jump(0, 10)
t.goto(0, -1 * width / 2)
# 方向0-东、90-北、180-西、270-南
t.setheading(0)
for i in range(9):
jump(-15, 9 - i)
t.fd(length / 2)
t.setheading(270)
for i in range(14):
jump(i - 14, 10)
t.fd(width / 2)
t.speed(9)
circle_star(-6, 8, 3 / 5)
circle_star(-4, 6, 1 / 7)
circle_star(-4, 3, -2 / 7)
circle_star(-6, 1, -4 / 5)
circle_star(-10, 8, 0, 6, 180)
t.Screen().bgcolor('red')
t.hideturtle()
t.done()