用python画星空, 绘制星空的过程中一般会用到海龟工具。属于Python的标准库,当然也可以叫龟库。可以用来描述绘图的轨迹,操作相对简单方便。
参考示例:
用python绘制星空的源代码介绍如下:
from turtle import *
from random import random,randint
screen=Screen()
width ,height=800,600
screen.setup(width,height)
Screen title (simulating three-dimensional (abbreviation of three dimension) starry sky)
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()
用python画星空,以上就是本文为您收集整理的用python画星空最新内容,希望能帮到您!更多相关内容欢迎关注。