python代码写好了怎么运行_Python「建议收藏」

python代码写好了怎么运行_Python「建议收藏」1.如何在python中做出星空效果呢?代码如下:fromturtleimport*fromrandomimportrandom,randintscreen=Screen()width,height=800,600screen.setup(width,height)screen.title(“模拟3D星空”)screen.bgcolor(“black”)screen.mode(“logo”)screen.delay(0)#这里要设为0,否则很卡t=Turtle(_星空代码

python代码写好了怎么运行_Python「建议收藏」

1.如何在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()

今天的文章python代码写好了怎么运行_Python「建议收藏」分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:http://bianchenghao.cn/58035.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注