用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、平安夜里送祝福,好运连连挡不住,身体健康劲头足,事业兴旺贵人助,财源广进腰包鼓,亲朋好友都和睦,新的一年更进步,每天过的...
句子查看全文>> -
没考ccna可以考ccie吗
很多朋友想知道没考ccna可以考ccie吗,下面就让我们来看看吧。可以,ccie虽然是思科认证中最高级别考试,但是没考ccna是可以直接考ccie的,ccie对学历、专业都没有...
科技查看全文>>
推荐
- 1奥迪a4epc灯亮车抖动370
- 2扶她是什么梗 扶他是什么意思196
- 3大众途安l真实成交价是多少?335
- 440岁女性签名135
- 5鸭蛋黄哪个牌子好 鸭蛋黄十大品牌排行榜126
- 6浪漫至死不渝的爱情句子169
- 7天籁正时皮带还是正时链条160
- 8灭火器简笔画怎么画307