猫史档案馆


【Python作品分享】【36强进10】明信片_高莫凡【作品秀】

用户:独立的星能猫_GEP独立的星能猫_GEP查看:0 回复:0 评论:0 创建时间:2021-05-23T20:18:07


【作品展示】

center_image

 

【作品介绍】

这个作品包含3张明信片,他们的主题分别是:新梦想,“星”征程,新家园。可以按空格键进行切换显示。

我的设计思路是,第一张“新梦想”是由之前编程猫课程的作品组合设计出来的。第二张“星”征程是在120强进36的基础上融合而来的,展现了中国航天人探索外太空的征程。第三张新家园,代表了对美好家园的想象,我希望在遥远的外太空也能找到和我们地球一样美丽的新家园。

 

【作品源代码】


# 中国航天
# 高莫凡

import turtle
import random
import time
w = turtle.Screen()
t = turtle.Pen()
t.ht()
fp = turtle.Pen()
fp.ht()
w.tracer(0)
t.speed(8)
WIDTH = 1920
HEIGHT = 1080
w.title("给航天人的明信片 ")
w.setup(WIDTH, HEIGHT, 0, 0)
w.bgcolor('black')


def moveto(x, y, pen=t):
    pen.pu()
    pen.goto(x, y)
    pen.pd()


def tri(s, c):
    t.fillcolor(c)
    t.seth(0)
    t.begin_fill()
    for i in range(3):
        t.lt(120)
        t.fd(s)
    t.end_fill()


def rect(w, h, c):
    t.seth(0)
    t.fillcolor(c)
    t.begin_fill()
    for i in range(2):
        t.fd(w)
        t.rt(90)
        t.fd(h)
        t.rt(90)
    t.end_fill()


def star(x, y, s, c="yellow"):
    moveto(x, y)
    t.color(c)
    t.begin_fill()
    for i in range(5):
        t.forward(s)
        t.right(144)
    t.end_fill()


def star1(x, y, s):
    moveto(x, y)
    t.color('yellow')
    t.begin_fill()
    for i in range(5):
        t.forward(s)
        t.left(144)
    t.end_fill()


def flag(x, y, s):
    t.seth(90)
    moveto(x, y)
    t.pencolor('red')
    rect(2*s, 4*s/3, 'red')
    big = s/10*5
    喵all = big/3
    # 主星
    x0 = x+s/10*2
    y0 = y-s/10*4
    star(x0, y0, big)
    # 副星1
    t.seth(305)
    x1 = 200/150*big
    y1 = 75/150*big
    star1(x0+x1, y0+y1, 喵all)
    # 副星2
    t.seth(30)
    x2 = 250/150*big
    y2 = -8/150*big
    star(x0+x2, y0+y2, 喵all)
    # 副星3
    t.seth(0)
    x3 = 250/150*big
    y3 = -75/150*big
    star(x0+x3, y0+y3, 喵all)
    # 副星4
    t.seth(300)
    x4 = 200/150*big
    y4 = -130/150*big
    star1(x0+x4, y0+y4, 喵all)


def bigRocket(x, y):
    moveto(x+50, y)
    tri(100, "white")
    moveto(x-50, y)
    rect(100, 10, "blue")
    moveto(x-50, y-10)
    rect(100, 500, "white")
    moveto(x-50, y-280)
    rect(100, 10, "blue")
    moveto(x-50, y-510)
    rect(100, 10, "blue")
    flag(x-40, y-30, 40)
    w = '中国航天飞向未来'
    px = x-20
    py = y-135
    t.color("blue")
    for i in w[0:4]:
        moveto(px, py)
        t.write(i, font=("文泉驿正黑", 30))
        py -= 45
    py -= 35
    for i in w[4:8]:
        moveto(px, py)
        t.write(i, font=("文泉驿正黑", 30))
        py -= 45


def littleRocket(x, y):
    t.pencolor("black")
    moveto(x, y)
    tri(50, "white")
    moveto(x-50, y)
    rect(50, 8, "blue")
    moveto(x-50, y-8)
    rect(50, 200, "white")
    moveto(x-50, y-170)
    rect(50, 8, "blue")


def trig1(x, y, s):
    moveto(x, y)
    t.fillcolor('white')
    t.begin_fill()
    t.seth(0)
    t.fd(s)
    t.lt(90)
    t.fd(s)
    t.end_fill()


def trig2(x, y, s):
    moveto(x, y)
    t.fillcolor('white')
    t.begin_fill()
    t.seth(180)
    t.fd(s)
    t.rt(90)
    t.fd(s)
    t.end_fill()


def fire(x, y, s):
    fp.pencolor('red')
    fp.pensize(3)
    moveto(x, y, fp)
    fp.fillcolor('red')
    fp.begin_fill()
    fp.seth(240)
    fp.fd(s)
    fp.rt(120)
    fp.fd(s)
    fp.end_fill()
    fp.pensize(1)


def circles(x, y, s):
    moveto(x, y)
    t.color('gray')
    t.dot(s)
    t.color('darkorange')
    t.dot(s-10)


def mars():
    # stop()
    moveto(WIDTH/2-200, -HEIGHT/2+150)
    t.color('darkorange')
    t.dot(1000)
    circles(WIDTH/2-400, -HEIGHT/2+500, 75)
    circles(WIDTH/2-500, -HEIGHT/2+400, 60)
    circles(WIDTH/2-250, -HEIGHT/2+450, 50)
    circles(WIDTH/2-375, -HEIGHT/2+250, 100)
    circles(WIDTH/2-200, -HEIGHT/2+300, 100)
    w.update()
    # time.sleep(1)
    flag(500, 175, 80)
    moveto(493, 175)
    t.pencolor('lightgray')
    rect(7, 375, 'lightgray')
    moveto(440, 200)
    t.pencolor('yellow')
    t.write('天问一号成功着陆火星!', font=("微软雅黑", 20))
    moveto(-650, 300)
    t.pencolor('white')
    t.write('中国追梦人,踏上"星"征程!', font=("幼圆", 30, "bold"))


def rocket():
    t.pencolor('black')
    bigRocket(0, 250)
    littleRocket(-50, -60)
    littleRocket(100, -60)
    trig1(-140, -268, 40)
    trig2(140, -268, 40)
    # fire(-喵,-275,22)
    # fire(83,-275,22)
    # fire(-17,-275,26)
    # fire(45,-275,26)
    # fire(19,-275,35)


def drawStar(starlist):
    # print(starlist)
    for st in starlist:
        star(st[0], st[1], st[2])


def moveStar(starlist):
    for st in starlist:
        st[1] -= 5
    for i in range(len(starlist)-1, -1, -1):
        if starlist[i][1] < -HEIGHT//2:
            starlist.pop(i)


def clear(starlist):
    for i in range(len(starlist)*16):
        t.undo()


def stop():
    global sp
    moveto(-95, -274)
    t.pencolor('black')
    t.seth(0)
    t.fillcolor('black')
    t.begin_fill()
    for i in range(2):
        t.fd(200)
        t.rt(90)
        t.fd(50)
        t.rt(90)
    t.end_fill()
    sp = 0


def fly():
    global sp
    fire(-喵, -275, 22)
    fire(83, -275, 22)
    fire(-17, -275, 26)
    fire(45, -275, 26)
    fire(19, -275, 35)
    sp = 1

# ==================== 星征程 =================


def journey():
    w.bgcolor("black")
    rocket()
    starlist = []
    starcount = 60
    count = 0
    fly()
    for i in range(200):
        # clear(starlist)
        if len(starlist) < starcount and count == 0:
            newstar = [
                random.randint(-WIDTH/2, WIDTH/2), HEIGHT/2, random.randint(8, 15)]
            if newstar[0] < -150 or newstar[0] > 150:
                starlist.append(newstar)
        moveStar(starlist)
        # time.sleep(0.005)
        count = (count+1) %8
    drawStar(starlist)
    w.update()
    mars()


# ==================== 新梦想 =================
def tele(a):
    t.seth(a)
    t.color("darkgoldenrod1")
    t.pensize(20)
    t.fd(50)
    t.color("darkgoldenrod2")
    t.pensize(30)
    t.fd(50)
    t.color("darkgoldenrod3")
    t.pensize(40)
    t.fd(50)
    t.color("gray")
    t.pensize(40)
    t.fd(1)
    t.color("lightcyan")
    t.pensize(30)
    t.fd(1)


def boy():
    t.dot(50)
    t.pensize(5)
    t.rt(90)
    t.fd(90)
    t.rt(30)
    t.fd(55)
    t.pu()
    t.fd(-55)
    t.pd()
    t.lt(60)
    t.fd(55)
    t.pu()
    t.fd(-55)
    t.pd()
    t.rt(30)
    t.pu()
    t.fd(-50)
    t.pd()

    t.lt(130)
    t.fd(55)
    t.pu()
    t.fd(-55)
    t.pd()
    t.rt(20)
    t.fd(55)


def bstar(s):
    t.pencolor("gold")
    t.fillcolor("gold")
    t.begin_fill()
    for i in range(5):
        t.forward(s)
        t.left(72)
        t.forward(s)
        t.right(144)
    t.end_fill()


def beidou():
    pos = [[0, 0], [-90, 20], [-200, -25], [100, -20], [150, -110], [240,-90], [240, 30]]
    s_list = [20, 11,14,5,8,11,17]
    for n in range(7):
        t.penup()
        t.goto(pos[n][0]+100, pos[n][1]+200)
        t.pendown()
        bstar(s_list[n])


def moon():
    t.penup()
    t.goto(-400, 300)
    t.pendown()
    t.pencolor("lightyellow")
    t.dot(100)
    t.forward(30)
    t.pencolor("midnightblue")
    t.dot(100)


def cardBorder():
    t.seth(0)
    moveto(-WIDTH/2+200, HEIGHT/2-130)
    t.pensize(25)
    t.pencolor("white")
    for i in range(2):
        t.fd(WIDTH-420)
        t.rt(90)
        t.fd(HEIGHT-320)
        t.rt(90)


def dream():
    w.bgcolor("midnightblue")
    moveto(-600, -150)
    t.color('gray')
    boy()
    moveto(-550, -160)
    tele(20)
    t.pensize(1)
    beidou()
    moon()
    moveto(50, -300)
    t.color("white")
    t.write("梦想有多大,世界就有多大!", font=("幼圆", 30, "bold"))


# ==================== 新家园 =================
def grass(x, y,s=10):
    t.seth(0)
    t.pencolor("green")
    t.pensize(15)
    moveto(x, y)    
    for i in range(3):
        t.lt(120)
        t.fd(15)
    moveto(x+20, y)    
    for i in range(3):
        t.lt(120)
        t.fd(15)
    moveto(x+45, y)    
    for i in range(3):
        t.lt(120)
        t.fd(25)
    moveto(x+60, y)    
    for i in range(3):
        t.lt(120)
        t.fd(15)


def ground():
    moveto(-900, -50)
    t.pencolor("orange3")
    rect(WIDTH-20, HEIGHT-320, "orange3")


def sky():
    moveto(-900, 550)
    t.pencolor("lightskyblue")
    rect(WIDTH-20, HEIGHT-320, "lightskyblue")


def grasses():
    grass(0, -200)
    grass(-300, -300)
    grass(300, -250)
    grass(-500, -250)

def leaf1(x, y):
    moveto(x, y)
    t.pensize(1)
    t.begin_fill()
    t.fillcolor("green")
    t.seth(-20)
    for i in range(40):
        t.fd(1)
        t.left(3)
    t.end_fill()
    t.seth(95)
    moveto(x, y)
    t.begin_fill()
    for i in range(40):
        t.fd(1)
        t.right(3)
    t.end_fill()

def leaf2(x, y):
    moveto(x, y)
    t.pensize(1)
    t.begin_fill()
    t.fillcolor("green")
    t.seth(-20+90)
    for i in range(40):
        t.fd(1)
        t.left(3)
    t.end_fill()
    t.seth(95+90)
    moveto(x, y)
    t.begin_fill()
    for i in range(40):
        t.fd(1)
        t.right(3)
    t.end_fill()

def flower(x, y):
    t.pensize(20)
    t.seth(0)
    star(x, y, 40, "pink")
    t.pensize(15)
    moveto(x+20, y-8)
    t.dot("red")
    t.pensize(7)
    t.pencolor("green")
    moveto(x+20, y-28)
    t.seth(270)
    t.fd(50)

    leaf1(x+24, y-60)
    leaf2(x+16, y-70)


def flowers():
    flower(-200, -100)
    flower(500, -150)
    flower(100, -250)
    flower(-400, -250)
    flower(-600, -200)


def house():
    moveto(200, 121)
    t.pencolor("pink")
    rect(200, 170, "pink")
    t.pencolor("blue")
    moveto(255, 85)
    rect(40, 40, "blue")
    moveto(305, 85)
    rect(40, 40, "blue")
    moveto(255, 35)
    rect(40, 40, "blue")
    moveto(305, 35)
    rect(40, 40, "blue")

    t.pencolor("brown")
    moveto(420, 121)
    tri(245, "brown")

    t.pencolor("brown")
    moveto(335, 285)
    rect(15, 45, "brown")

def earth():
    moveto(-600, 300)
    t.pencolor("blue")
    t.dot(150)

    moveto(-650, 270)
    t.pencolor("white")
    t.color("white")
    t.write("地球", font=("微软雅黑", 40))


def home():
    sky()
    ground()
    grasses()
    flowers()
    house()
    # trees()
    earth()
    moveto(-550, 0)
    t.color("darkgreen")
    t.write("在未来,或许我们会有新的家园!", font=("幼圆", 30, "bold"))


w.tracer(0)
def changeCard():
    global cn
    print("changeCard", cn)
    cn = (cn+1)%3
    if cn == 0:
        t.clear()
        dream()
    if cn == 1:
        t.clear()
        journey()
    if cn == 2:
        t.clear()
        fp.clear()
        home()
    w.update()


def start():
    w.bgcolor("black")
    t.pencolor('yellow')
    moveto(-WIDTH/2+250, 200)
    t.write('可爱的航天人:', font=("微软雅黑", 30))
    moveto(-WIDTH/2+350, 100)
    t.write('下面是3张我给你的明信片,请按空格进行切换。', font=("微软雅黑", 30))
    moveto(-WIDTH/2+350, 0)
    t.write('三张明信片的主题分别是: "新梦想", "星征程", "新家园"', font=("微软雅黑", 30))
    w.update()
    # sp = 0


cn = -1
turtle.tracer(0)
start()
w.listen()
w.onkey(changeCard, "space") 

w.update()
turtle.done()

 

【提示】

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

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页