用户:
独立的星能猫_GEP查看:0 回复:1 评论:0 创建时间:2021-05-16T13:40:26
【作品展示】

【作品介绍】
作品运行后,首先显示宇宙飞船,可以按键执行不同的任务:按数字“1”键,起飞;
按数字“2”键,飞往火星,插上五星红旗;
按数字“3”键,暂停飞行。
【作品源代码】
# 中国航天
# 高莫凡
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):
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):
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.write('天问一号成功着陆火星!',font=("微软雅黑", 20))
time.sleep(4)
for i in range(5*16):
t.undo()
for i in range(90):
t.undo()
fly()
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
rocket()
starlist = []
starcount = 60
count = 0
moveto(-WIDTH/2+250, HEIGHT/2-150)
t.pencolor('white')
t.write('请按数字键执行不同任务: 1 - fly 2 - goto MARS 3 - stop',font=("微软雅黑", 15))
w.update()
sp = 0
w.listen()
w.onkeypress(fly,1)
w.onkeypress(mars,2)
w.onkeypress(stop,3)
while True:
if sp == 1:
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)
drawStar(starlist)
# rocket()
w.update()
moveStar(starlist)
time.sleep(0.005)
count = (count+1)%8
else:
time.sleep(0.5)
w.update()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn