用户:Emily@love查看:0 回复:0 评论:0 创建时间:2024-05-25T19:18:09
【作品展示】

【作品介绍】
它可以显示出火箭是怎么飞到火星的,然后它又被测量出温度是多少,最后可以解决种树的问题。
【作品源代码】
import turtle as t
import time
import random
t.setup(width=800, height=600)
t.title("出发火星")
t.bgpic('太空.gif')
'''前往火星的剧情设计'''
#飞船前进
#添加好外形
shape_list = ["飞天号.gif", "地球.gif", "小火星.gif"]
for i in shape_list:
t.addshape(i)
#地球画笔
p = t.Pen()
p.shape('地球.gif')
p.ht()
p.penup()
#火星画笔
p2 = t.Pen()
p2.shape('小火星.gif')
p2.ht()
p2.penup()
#飞船画笔
p3 = t.Pen()
p3.shape('飞天号.gif')
p3.ht()
p3.penup()
#摆放好初始位置
p.goto(-300, -150)
p2.goto(300, 200)
p3.goto(-200, -90)
p.st()
p2.st()
p3.st()
print('⚠ 我们正在进入地火轨道前往火星!')
#前往火星 代码1:
# for i in range(250):
# p3.forward(1)
# p3.left(0.1)
# print('⚠ 我们将于10分钟后降落火星,请先通过火星地图再次确保熟悉火星地形!!')
# for i in range(300):
# p3.forward(1)
# p3.left(0.1)
#前往火星 代码2:
p3.speed(1)
p3.forward(120)
print('⚠ 我们将于10分钟后降落火星,请先通过火星地图再次确保熟悉火星地形!!')
p3.circle(300,90)
p.ht()
p2.ht()
p3.ht()
# import 火星
t.setup(width=800, height=600)
t.title("勘测火星地形")
t.bgpic('火星.gif')
wn = t.Screen()
p = t.Pen()
p.penup()
p.ht()
'''绘制不同地点'''
dict = {"水手峡谷": (100, 50), "奥林匹斯山": (-175, -85)}
for key, val in dict.items():
p.goto(val[0], val[1])
p.dot(25, 'red')
p.write(key)
'''预置地貌图片'''
img = t.Pen()
img.penup()
img.ht()
for i in dict.keys():
t.addshape(i+".gif")
'''定义点击事件'''
def fn(x, y):
threshold = 100
for key, val in dict.items():
if (x - val[0])**2 + (y - val[1])**2 <= threshold:
img.ht()
img.shape(key + ".gif")
loc = dict.get(key)
img.goto(loc[0], loc[1])
img.st()
wn.onclick(fn)
text = "⚠为了能够实现适宜人类生存的生态环境,你要做的是需要在基地中调节各种指数,比如大气中各种气体含量、温度、光照。"
print(text)
val1 = int(input("请输入大气中的氧气浓度(例如:20)【范围:0-100%】:"))
'''准备不同的结局'''
t.setup(width=800, height=600)
t.title("火星家园")
t.bgpic('火星表面.gif')
'''条件分支判断进入哪个结局'''
if val1 > 20:
img = t.Pen()
img_list = ["树木.gif", "小鸟.gif", "宇航员.gif"]
for i in img_list:
t.addshape(i)
location = [(200, -30), (-100, 150), (-100, -100)]
img.penup()
for i in range(len(img_list)):
img.goto(location[i][0], location[i][1])
img.shape(img_list[i])
img.stamp()
t.done()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn