python星空代码_用python画星空源代码是什么?

 2023-09-17 阅读 27 评论 0

摘要:用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"

5eeb154c1cd4b532.jpg

用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()

1592464829111414.png

以上就是用python画星空源代码是什么?的详细内容,更多请关注php中文网其它相关文章!

article_wechat2021.jpg?1111

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/3/72490.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息