五星红旗

import turtle

设置画布大小

turtle.setup(600, 400)

设置画笔速度

turtle.speed(10)

绘制红色背景

turtle.penup()
turtle.goto(-300, 200)
turtle.pendown()
turtle.color("red")
turtle.begin_fill()
for _ in range(2):
turtle.forward(600)
turtle.right(90)
turtle.forward(400)
turtle.right(90)
turtle.end_fill()

绘制大五角星

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

draw_star(-200, 100, 100)

绘制四个小五角星

def draw_small_star(x, y, radius):
turtle.penup()
turtle.goto(x, y)
turtle.setheading(0)
turtle.pendown()
turtle.color("yellow")
turtle.begin_fill()
for _ in range(5):
turtle.forward(radius)
turtle.right(144)
turtle.end_fill()

draw_small_star(-100, 150, 30)
draw_small_star(-60, 120, 30)
draw_small_star(-60, 70, 30)
draw_small_star(-100, 40, 30)

隐藏画笔

turtle.hideturtle()

结束绘制

turtle.done()

posted @ 2025-03-09 16:20  Xxxjxxx  阅读(14)  评论(0)    收藏  举报