下面是一个用Python绘制中国国旗的例子:

import turtle

def draw_rectangle(x, y, width, height, color):
    turtle.penup()
    turtle.goto(x, y)
    turtle.fillcolor(color)
    turtle.begin_fill()
    for _ in range(2):
        turtle.forward(width)
        turtle.right(90)
        turtle.forward(height)
        turtle.right(90)
    turtle.end_fill()

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

def draw_china_flag():
    turtle.speed(1)
    turtle.hideturtle()
    
    # 绘制红色背景
    draw_rectangle(-250, 200, 500, 300, "red")
    
    # 绘制大星星
    draw_star(-110, 40, 40, "yellow")
    
    # 绘制四颗小星星
    positions = [(-80, 80), (-60, 0), (-80, -80), (-120, -80)]
    for position in positions:
        draw_star(position[0], position[1], 15, "yellow")

if __name__ == "__main__":
    draw_china_flag()
    turtle.done()

运行上述代码,将会在窗口中绘制中国国旗


原文地址: https://www.cveoy.top/t/topic/iykD 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录