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

阅读剩余部分

相关阅读 >>

字符串格式化 % vs format哪种更好

Python函数之classmethod()

Python文本特征抽取与向量化算法学习实例详解

Python中paramiko模块实现远程控制以及传输的示例

Python中if 条件判断代码解析

Python比php好在哪?

Python实现对指定输入的字符串逆序输出的方法

Python实现rsa算法

Python如何修改dataframe列名

多版本Python共存的配置方法

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




打赏

取消

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

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

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

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

评论

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