page contents

用python画梵高星空的代码

本文讲述了用Python画梵高星空的代码!具有很好的参考价值,希望对大家有所帮助。一起跟随六星小编过来看看吧,具体如下:

attachments-2022-12-ACT5UEhX639140852b2ee.jpg本文讲述了用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编程学习圈。每天分享行业资讯、技术干货供大家阅读,关注即可免费领取整套Python入门到进阶的学习资料以及教程,感兴趣的小伙伴赶紧行动起来吧。

attachments-2022-05-rLS4AIF8628ee5f3b7e12.jpg

  • 发表于 2022-12-08 09:40
  • 阅读 ( 1492 )
  • 分类:Python开发

你可能感兴趣的文章

相关问题

0 条评论

请先 登录 后评论
王昭君
王昭君

209 篇文章

作家榜 »

  1. 轩辕小不懂 2403 文章
  2. 小柒 1312 文章
  3. Pack 1135 文章
  4. Nen 576 文章
  5. 王昭君 209 文章
  6. 文双 71 文章
  7. 小威 64 文章
  8. Cara 36 文章