import turtle

设置画布和画笔

screen = turtle.Screen()
screen.setup(width=800, height=533) # 国旗比例 3:2
pen = turtle.Turtle()
pen.speed(10)
pen.hideturtle()

绘制红色旗面

pen.penup()
pen.goto(-400, 266)
pen.pendown()
pen.color("red")
pen.begin_fill()
for _ in range(2):
pen.forward(800)
pen.right(90)
pen.forward(533)
pen.right(90)
pen.end_fill()

定义绘制五角星的函数

def draw_star(pen, x, y, radius):
pen.penup()
pen.goto(x, y)
pen.setheading(0)
pen.forward(radius)
pen.setheading(162)
pen.pendown()
pen.color("yellow")
pen.begin_fill()
for _ in range(5):
pen.forward(2 * radius * 0.382)
pen.right(144)
pen.end_fill()

绘制大五角星

big_star_x = -320
big_star_y = 180
big_star_radius = 60
draw_star(pen, big_star_x, big_star_y, big_star_radius)

小五角星的位置和角度

small_stars_info = [
(-200, 240, 315),
(-160, 200, 30),
(-160, 140, 0),
(-200, 100, 330)
]

绘制小五角星

small_star_radius = 20
for x, y, angle in small_stars_info:
pen.penup()
pen.goto(x, y)
pen.setheading(angle)
pen.forward(small_star_radius)
pen.setheading(pen.heading() + 162)
pen.pendown()
pen.color("yellow")
pen.begin_fill()
for _ in range(5):
pen.forward(2 * small_star_radius * 0.382)
pen.right(144)
pen.end_fill()

完成绘制

turtle.done()

posted on 2025-03-03 11:59  1235yyq  阅读(16)  评论(0)    收藏  举报