用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()
-
幸福心情好的句子大全
1、幸福是怀有一颗感恩的心;有一个健康的身体;一帮值得信赖的朋友和一个充满希望的明天。2、朦胧中感到父亲的关怀,徐徐的风儿撩起窗纱;隐约中听到母亲的叮咛,柔柔的雨儿爬上窗台。当...
句子查看全文>> -
古风古韵家族名字三字
三字古风古韵家族名字有哪些呢?我们一起来看一看:1、古风古韵家族名字三字带符号☼何惧情▶绾紫淑☺楼露绮旧人归映萧羽♘相思劫▶代替品类似情☼枫无痕再回首✪☺梦冥光挽✪兰芷♡莎莎兔...
生活查看全文>> -
b2驾驶证扣了3分怎么办
b2驾驶证扣了3分解决方法:去当地的车管所或者是交通部门将罚款缴纳清除,一般来说B2驾驶证被扣三分是需要去进行为期三小时的学习,这个学习是要在年审的时候去学的。机动车驾驶员在记...
问答查看全文>>
推荐
- 1红旗名仕发动机多少钱?254
- 2冠道卤素大灯可以换led吗?233
- 3对于刚拿到驾照的新手,是买便宜的新车练手好还是先买二手车好?362
- 4科目三掉头步骤踩什么?329
- 5全新一代创酷试驾怎么样?257
- 6立式减速机用什么油?172
- 7大众捷达发动机盖子怎么打开?327
- 8玛莎拉蒂总裁声浪大小怎么调?375