用python画星空
用python画星空是怎样的呢?下面就让我们一起来了解一下吧:
在绘制星空的过程中一般需要运用到turtle工具,它是属于Python的标准库,当然也可以将其称之为海龟库,它能够用于描绘绘图的轨迹,并且操作也比较简单、便捷。
参考范例:
用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()
-
宝骏510公里数在哪里看?
宝骏510公里数在仪表盘上看,以宝骏510的2021款1.5L手动乐享型为例:其是一款小型5门5座SUV,长宽高分别为4220mm、1740mm、1625mm,轴距为2550m...
问答查看全文>> -
异地违停怎么处理能在本地办理吗?
目前车辆违章处理,车主需要携带驾驶证和行驶证到车辆违规地或车辆登记所在地的任何交警队或行政综合处理大厅都可以接受处理:1、如违规未扣分,可直接到工行自助支付机或网上支付罚款,可...
问答查看全文>>
推荐
- 1充满少女心甜甜的句子 关于少女心的句子147
- 2内循环怎么用179
- 3双胞胎取名大全242
- 4欧拉r1蓝牙钥匙连不上怎么办?354
- 5老款别克凯越暖风的打开方法是什么?389
- 6外地车限行时间怎么开?268
- 7华为赛力斯华为占多少股份?赛力斯华为有股份吗103
- 8有关单身的句子380
家常菜
- 1竹叶石膏汤加(低热不退者)439
- 2迷迭香起司义式酥饼390
- 3姜楂萝卜子粥444
- 4椒盐带鱼171
- 5白酱蘑菇意大利面+鱼扒109
- 6肉松米糊217
- 7雪耳木瓜奶露469
- 8凉拌金针菇162