用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/2randint(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/2randint(1,width))
star.sety( randint(-height/2,height/2))
star.showturtle()
以上是小编的分享 , 希望对大家有所帮助 。
【用python画星空是怎样的? 用python画星空】
- 如何创建一个好的用户ID 用户ID是什么意思解释
- 隋炀帝开辟的京杭大运河 隋朝大运河现在还在用吗
- yc
- 参数配置使用下来的感受 vivo手机x60测评怎么样
- 用天语云智能手机w700让你更加轻松畅快地生活
- 发膜的正确使用方法
- 南非的通用语言是什么
- 离合器的作用 汽车离合器的原理和作用是怎样的_酷知科普
- 诺基亚官方网站:用科技创造更美好的未来
- 养花的花盆有讲究吗?哪些花盆不能用来养花?
