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


本文摘自php中文网,作者coldplay.xixi,侵删。

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

用python画星空源代码如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

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

阅读剩余部分

相关阅读 >>

tuple和list中,为什么只有前者才可以作为字典的key?

Python实战爬虫视频教程的资料推荐

Python列表的基本操作有哪些

介绍Python的抖音快手字符舞

Python的元类如何使用

Python字典中如何一键多值的写入?

Python如何比较两个列表

Python实现自定义顺序、排列写入数据到excel的方法

解决Python基于回溯法子集树模板实现8皇后问题

Python语言是由哪个人创造的

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...