五星红旗

import turtle

def draw_rectangle(x, y, width, height, color):
turtle.penup()
turtle.goto(x, y)
turtle.pendown()
# 设置画笔颜色与填充颜色相同,去除边框
turtle.pencolor(color)
turtle.fillcolor(color)
turtle.begin_fill()
for _ in range(2):
turtle.forward(width)
turtle.left(90)
turtle.forward(height)
turtle.left(90)
turtle.end_fill()

def draw_star(x, y, radius, color):
turtle.penup()
turtle.goto(x, y)
turtle.pendown()
# 设置画笔颜色与填充颜色相同,去除边框
turtle.pencolor(color)
turtle.fillcolor(color)
turtle.begin_fill()
for _ in range(5):
turtle.forward(radius)
turtle.right(144)
turtle.end_fill()

def main():
turtle.speed(0)
# 绘制旗面
draw_rectangle(-300, -200, 600, 400, 'red')
# 绘制大五角星
draw_star(-200, 100, 50, 'yellow')
# 计算小五角星的位置,这里只是简单示意,实际需要精确计算角度和位置
small_star_positions = [
(-100, 150),
(-80, 110),
(-80, 70),
(-100, 30)
]
for pos in small_star_positions:
draw_star(pos[0], pos[1], 20, 'yellow')
turtle.hideturtle()
turtle.done()

if name == "main":
main()

posted @ 2025-02-25 14:21  林leo  阅读(37)  评论(0)    收藏  举报