Use python code to draw a starry sky, and use python to draw a dynamic starry sky

Hello everyone, the editor will answer the following questions for you, use python code to draw a starry sky, and use python to draw a dynamic starry sky, let's take a look now!

The effect is as shown in the figure (parameters such as line thickness, color, star position, etc. can be adjusted freely/randomly):
insert image description here
insert image description here
insert image description here

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

Guess you like

Origin blog.csdn.net/mynote/article/details/132448388