python之星空代码

1.如何在python中做出星空效果呢?

代码如下:from turtle import *
from random import random,randint
screen = Screen()
width ,height = 800,600
screen.setup(width,height)
screen.title(“模拟3D星空”)
screen.bgcolor(“black”)
screen.mode(“logo”)
screen.delay(0)#这里要设为0,否则很卡
t = Turtle(visible = False,shape=‘circle’)
t.pencolor(“white”)
t.fillcolor(“white”)
t.penup()
t.setheading(-90)
t.goto(width/2,randint(-height/2,height/2))
stars = []
for i in range(200):
star = t.clone()
s =random() /3
star.shapesize(s,s)
star.speed(int(s*10))
star.setx(width/2 + randint(1,width))
star.sety( randint(-height/2,height/2))
star.showturtle()
stars.append(star)
while True:
for star in stars:
star.setx(star.xcor() - 3 * star.speed())
if star.xcor()<-width/2:
star.hideturtle()
star.setx(width/2 + randint(1,width))
star.sety( randint(-height/2,height/2))
star.showturtle()

  • 1
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
对于python绘制星空代码,你可以使用plotly库来实现。首先,你需要导入plotly包,并定义你的用户名和API Key。然后,你可以使用plotly的绘图函数来创建一个星空主题的旅游线路图。具体的绘制过程包括选择绘图模式、读取起点和终点的经纬度,并生成曲线连接这两个坐标。最后,你可以对图像进行美化,如调整尺寸、颜色等。 下面是python绘制星空代码的示例: ```python import plotly import plotly.graph_objs as go # 定义用户名和API Key plotly.tools.set_credentials_file(username='your_username', api_key='your_api_key') # 创建一个空列表 data = [] # 遍历每条数据,读取起点和终点的经纬度,生成曲线 for i in range(len(locations)): trace = go.Scattergeo( locationmode = 'country names', lon = [start_lon[i], end_lon[i]], lat = [start_lat[i], end_lat[i]], mode = 'lines', line = dict(width = 2, color = 'red'), name = 'Airline {}'.format(i+1) ) data.append(trace) # 绘制图像 layout = dict( title = 'Starry Sky Travel Routes', showlegend = False, geo = dict( showland = True, landcolor = 'rgb(240, 240, 240)', countrycolor = 'rgb(204, 204, 204)', coastlinecolor = 'rgb(204, 204, 204)', projection = dict( type = 'natural earth' ), lonaxis = dict( showgrid = True, gridwidth = 0.5, range= [ -140.0, -55.0 ], dtick = 5 ), lataxis = dict ( showgrid = True, gridwidth = 0.5, range= [ 20.0, 60.0 ], dtick = 5 ) ) ) fig = dict(data=data, layout=layout) plotly.offline.plot(fig, filename='star_travel_routes.html') ``` 你可以根据你的具体需求进行代码的修改和美化。这段代码可以绘制出一个星空主题的旅游线路图,并保存为HTML文件。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值