用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()
-
揭秘黄瓜内有弓形虫的真相 黄瓜去农药残留好办法
一则关于&ldquo黄瓜内有弓形虫&rdquo的视频被纷纷转发,视频显示有人从显微镜中观察黄瓜的汁液,发现其中有较多的弓形虫,还称这种寄生虫在260摄氏度的高温下也杀灭不掉,而...
冷知识查看全文>> -
这条街最靓的仔是什么意思 这条街最靓的仔是什么梗
这条街最靓的仔,也就是做街上最酷的人的意思。这条街最靓的仔,让小编想起林更新“九亿少女的梦”这个梗。(只要你乖给你买条gai:3665.html)这条街最靓的仔,该梗是一张虚化...
热词查看全文>> -
手机迅雷在哪里面对面传视频
当我们在手机上下载好一部电影,怎么样操作才能把它传到另一部手机里面,手机迅雷里面的面对面快传是怎么操作的呢,别急,想要知道手机迅雷怎么面对面传视频,就来看看今天的视频吧,本视频...
科技查看全文>>
推荐
- 1经典轩逸轮胎多久更换一次?367
- 22022餐饮调查报告范文103
- 3赫根奶瓶怎么开盖 赫根奶瓶防胀气效果好吗424
- 4长安凌轩用了什么变速箱119
- 5缤智是什么品牌旗下的suv427
- 6种草莓是什么意思351
- 7车用汽油的标号是根据什么确定的?451
- 8湖南天心阁的导游词范文185