猫史档案馆


【Python作品分享】【去太空,趣编程】中国航天,飞向未来【作品秀】

用户:独立的星能猫_GEP独立的星能猫_GEP查看:0 回复:1 评论:0 创建时间:2021-05-05T19:09:06


【作品展示】

center_image

 

【作品介绍】

我叫高莫凡,这是我用python turtle画的中国航天在太空中飞向未来的作品。

 

【作品源代码】

# 中国航天
# 高莫凡

import turtle as t
import random
import time
t.speed(8)
WIDTH = 1920
HEIGHT = 1080
t.title("中国航天")
t.setup(WIDTH,HEIGHT, 0, 0)
t.bgcolor('black')
t.ht()

def moveto(x, y):
    t.pu()
    t.goto(x,y)
    t.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):
    moveto(x, y)
    t.color('yellow')
    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):
    t.pencolor('red')
    t.pensize(3)
    moveto(x,y)
    t.fillcolor('red')
    t.begin_fill()
    t.seth(240)
    t.fd(s)
    t.rt(120)
    t.fd(s)
    t.end_fill()
    t.pensize(1)

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()

rocket()
t.tracer(0)
t.update()
starlist = []
starcount = 60
count = 0
while True:
    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)    
    drawStar(starlist)    
    # rocket()
    t.update()
    moveStar(starlist)
    time.sleep(0.005)
    clear(starlist)
    count = (count+1)%8

t.done()

 

【提示】

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

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
我是曲奇饼干我是曲奇饼干

烈害,竞争对手+1

点赞0


评论