用python代码画出一片星空,用python绘制满天星动态

大家好,小编来为大家解答以下问题,用python代码画出一片星空,用python绘制满天星动态,现在让我们一起来看看吧!

效果如图(可自由/随机调整线条粗细、颜色、星星位置等参数):
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

from turtle import *
import random

def cell(l1):
    down()
    for i in range(6):
        forward(l1)
        left(60)
        forward(l1)
        right(120)
    up()
    
t = 1
speed(10)

# The sky will full of stars
def lrk(l1,l2): 
    up()
    width(random.randint(1,4))
    colormode(255)
    color(random.randint(0,255),random.randint(0,255),random.randint(0,255))
    goto(random.randint(0,300),random.randint(0,300))
    cell(l1)
    global t
    t = not t
    if l1/3 < l2:
        return
    elif t == 1:
        l1 *= random.randint(1,2)
    else:
        l1 /= random.randint(1,4)
    lrk(l1,l2)

lrk(10,0.1) #testing
done()

猜你喜欢

转载自blog.csdn.net/mynote/article/details/132448388