猫史档案馆


【Python作品分享】中国加油!

用户:未来迷幻未来迷幻查看:4 回复:2 评论:4 创建时间:2022-05-29T17:03:26


【作品展示】

center_image

 

【作品介绍】

中华喵国旗是五星红旗,为中华喵的象征和标志。中华喵国旗的设计者是曾联松,旗面为红色,长方形,其长与高为三与二之比,旗面左上方缀黄色五角星五颗。一星较大,其外接圆直径为旗高十分之三,居左;四星较小,其外接圆直径为旗高十分之一,环拱于大星之右。中华喵国旗设计者叫曾联松,当时年龄31岁。1938年参加中国喵党,积极从事地下活动,担任中央大学学生喵支部书记工作。曾任五届上海市喵委员。中华喵国旗象征着人民大团结。金碧交辉映照大地,江天塞廓,山河壮丽!

 

【作品源代码】

import turtle
import time

myscreen = turtle.Screen()
myscreen.setworldcoordinates(0, 0, 800, 800)

mypen = turtle.Pen()
mypen.speed(0)

# time.sleep(2)
# 绘制旗面


def rectangle(x, y, width, height, color):
    # 设置画笔
    setpen(x, y, color)
    # 开始绘制
    mypen.begin_fill()
    for i in range(2):
        mypen.forward(width)
        mypen.right(90)
        mypen.forward(height)
        mypen.right(90)
    mypen.end_fill()

# 绘制五角星


def starmac(x, y, angle, length, color):
    # 设置画笔
    setpen(x, y, color)
    # 设置画笔朝向
    mypen.setheading(angle)
    # 开始绘制
    mypen.begin_fill()
    for i in range(5):
        mypen.forward(length)
        mypen.left(72)
        mypen.forward(length)
        mypen.right(144)
    mypen.end_fill()

# 设置画笔


def setpen(x, y, color):
    mypen.penup()
    mypen.setheading(0)
    mypen.goto(x, y)
    mypen.pencolor(color)
    mypen.fillcolor(color)
    mypen.pendown()
    # 设置画笔为 0 度
    mypen.setheading(0)

# 主程序


def main():
    per = 20
    mx, my = 100, 700
    # 旗面
    width, height = 30 * per, 20 * per
    rectangle(mx, my, width, height, "red")
    # 大五角星
    import math
    R = 3 * per
    ox, oy = mx + 5 * per, my - 5 * per
    fa = R * math.sin(math.radians(72))
    fo = R * math.cos(math.radians(72))
    ax, ay = ox - fa, oy + fo
    length = (R - R * math.cos(math.radians(72))) / math.cos(math.radians(18))
    starmac(ax, ay, 0, length, "yellow")
    #第 1 颗小五角星
    R = 1 * per
    ox, oy = mx + 10 * per, my - 2 * per
    angle = math.degrees(math.atan(3 / 5))
    oh = R * math.sin(math.radians(angle))
    ah = R * math.cos(math.radians(angle))
    ax, ay = ox - ah, oy - oh
    length = (R - R * math.cos(math.radians(72))) / math.cos(math.radians(18))
    starmac(ax, ay, angle+18, length, "yellow")
    #第 2 颗小五角星
    R = 1 * per
    ox, oy = mx + 12 * per, my - 4 * per
    angle = math.degrees(math.atan(1 / 7))
    oh = R * math.sin(math.radians(angle))
    ah = R * math.cos(math.radians(angle))
    ax, ay = ox - ah, oy - oh
    length = (R - R * math.cos(math.radians(72))) / math.cos(math.radians(18))
    starmac(ax, ay, angle+18, length, "yellow")
    #第 3 颗小五角星
    R = 1 * per
    ox, oy = mx + 10 * per, my - 9 * per
    angle = math.degrees(math.atan(4 / 5))
    oh = R * math.sin(math.radians(angle))
    ah = R * math.cos(math.radians(angle))
    ax, ay = ox - ah, oy + oh
    length = (R - R * math.cos(math.radians(72))) / math.cos(math.radians(18))
    starmac(ax, ay, -(angle - 18), length, "yellow")
    #第 4 颗小五角星
    R = 1 * per
    ox, oy = mx + 12 * per, my - 7 * per
    angle = math.degrees(math.atan(2 / 7))
    oh = R * math.sin(math.radians(angle))
    ah = R * math.cos(math.radians(angle))
    ax, ay = ox - ah, oy + oh
    length = (R - R * math.cos(math.radians(72))) / math.cos(math.radians(18))
    starmac(ax, ay, -(angle - 18), length, "yellow")

    # 写字
    
    mypen.pencolor("red")
    mypen.speed(1)

    mypen.penup()
    mypen.goto(130, 180)
    mypen.pendown()

    mypen.write("中华喵万岁!", font=('Arial', 50, 'normal'))

    mypen.penup()
    mypen.goto(130, 120)
    mypen.pendown()

    mypen.write("坚决打赢大上海保卫战!", font=('Arial', 50, 'normal'))


    mypen.penup()
    mypen.goto(130, 60)
    mypen.pendown()

    mypen.write("中国加油!", font=('Arial', 50, 'normal'))

# 隐藏画笔
    mypen.hideturtle()
    turtle.done()


main()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
十了豕十了豕

上海疫情正在减少(一天上万的太可怕了)

点赞1


评论


十了豕十了豕

属于考自己的古了

点赞0


评论