Python 3's tutle painting imitates the 3d star sky, the moving star universe

This article refers to the original- http://bjbsair.com/2020-03-25/tech-info/6248/ 1. universe

2. Code implementation conditions

python3

3. first steps:

#---Step 1 - import module---  
from turtle import *  
from random import random,randint

4. second steps:

#---Step 2 - initialization definition---  
#---Define screen, window size, title, background color  
screen = Screen()  
#---Bigger, better---  
width ,height = 1600,1200  
screen.setup(width,height)  
screen.title('Romantic starry sky')  
screen.bgcolor("black")  
#Sets or returns the drawing delay in milliseconds, the greater the delay, the slower the drawing  
screen.delay(0)

5. third steps:

#---Step 3: define three different colors of stars with different sizes, speeds, positions and shapes---  
#shape(): set the shape of the tortoise. The values are: "arrow", "turn", "circle", "square", "triangle", "classic"  
#---Stars - white stars---  
t = Turtle(visible = False,shape='circle')  
t.pencolor("white")  
#The color of a turtle, the color of a flying planet  
t.fillcolor("blue")  
t.penup()  
#Rotation angle  
t.setheading(-10)  
#Coordinates are random  
t.goto(width/2,randint(-height/2,height/2))  
  
#---Star 2 - little green star in the distance---  
t2 = Turtle(visible = False,shape='turtle')  
#The color of a turtle, the color of a flying planet  
t2.fillcolor("green")  
t2.penup()  
t2.setheading(-50)  
#Coordinates are random  
t2.goto(width,randint(-height,height))  
  
#---Star 3 - near Red Star---  
t3 = Turtle(visible = False,shape='circle')  
#The color of a turtle, the color of a flying planet  
t3.fillcolor("red")  
t3.penup()  
t3.setheading(-90)  
#Coordinates are random  
t3.goto(width*2,randint(-height*2,height*2))

6. fourth steps:

#---Step 4 - define planet list - for storage---  
stars = []  
stars2 = []  
stars3 = []

7. fifth steps:

#---Step 5: define the size, speed and location of three kinds of stars and store them in their respective lists---  
#---Pay attention to 200 and quit for drawing 200 planets. Too many of them are stuck---  
for i in range(200):  
    star = t.clone()  
    #Determine the size of the planet  
    s= random()/3  
    star.shapesize(s,s)  
    star.speed(int(s*10))  
    #Randomly generated coordinates  
    star.setx(width/2 + randint(1,width))  
    star.sety(randint(-height/2,height/2))  
    star.showturtle()  
    stars.append(star)  
  
for i in range(200):  
    star2 = t2.clone()  
    #Determine the size of the planet  
    s2= random()/2  
    star2.shapesize(s2,s2)  
    star2.speed(int(s*10))  
    star2.setx(width/2 + randint(1,width))  
    star2.sety(randint(-height/2,height/2))  
    star2.showturtle()  
    stars2.append(star2)  
  
for i in range(200):  
    star3 = t3.clone()  
    #Determine the size of the planet  
    s3= random()*5  
    star3.shapesize(10*s3,10*s3)  
    star3.speed(int(s3*10))  
    star3.setx(width*2 + randint(1,width))  
    star3.sety(randint(-height*2,height*2))  
    star3.showturtle()  
    stars3.append(star3)

8. sixth steps:

#---Step 6 - game cycle - start of each planet  
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()  
  
    for star2 in stars2:  
        star2.setx(star2.xcor() - 3 * star2.speed())  
        if star2.xcor()<-width/2:  
            star2.hideturtle()  
            star2.setx(width/2 + randint(1,width))  
            star2.sety( randint(-height/2,height*2))  
            star2.showturtle()  
  
    for star3 in stars3:  
        star3.setx(star3.xcor() - 3 * star3.speed())  
        if star3.xcor()<-width*2:  
            star3.hideturtle()  
            star3.setx(width*2 + randint(1,width))  
            star3.sety( randint(-height*2,height*2))  
            star3.showturtle()

9. effect picture

This article refers to the original- http://bjbsair.com/2020-03-25/tech-info/6248/ 1. universe

2. Code implementation conditions

python3

3. first steps:

#---Step 1 - import module---  
from turtle import *  
from random import random,randint

4. second steps:

#---Step 2 - initialization definition---  
#---Define screen, window size, title, background color  
screen = Screen()  
#---Bigger, better---  
width ,height = 1600,1200  
screen.setup(width,height)  
screen.title('Romantic starry sky')  
screen.bgcolor("black")  
#Sets or returns the drawing delay in milliseconds, the greater the delay, the slower the drawing  
screen.delay(0)

5. third steps:

#---Step 3: define three different colors of stars with different sizes, speeds, positions and shapes---  
#shape(): set the shape of the tortoise. The values are: "arrow", "turn", "circle", "square", "triangle", "classic"  
#---Stars - white stars---  
t = Turtle(visible = False,shape='circle')  
t.pencolor("white")  
#The color of a turtle, the color of a flying planet  
t.fillcolor("blue")  
t.penup()  
#Rotation angle  
t.setheading(-10)  
#Coordinates are random  
t.goto(width/2,randint(-height/2,height/2))  
  
#---Star 2 - little green star in the distance---  
t2 = Turtle(visible = False,shape='turtle')  
#The color of a turtle, the color of a flying planet  
t2.fillcolor("green")  
t2.penup()  
t2.setheading(-50)  
#Coordinates are random  
t2.goto(width,randint(-height,height))  
  
#---Star 3 - near Red Star---  
t3 = Turtle(visible = False,shape='circle')  
#The color of a turtle, the color of a flying planet  
t3.fillcolor("red")  
t3.penup()  
t3.setheading(-90)  
#Coordinates are random  
t3.goto(width*2,randint(-height*2,height*2))

6. fourth steps:

#---Step 4 - define planet list - for storage---  
stars = []  
stars2 = []  
stars3 = []

7. fifth steps:

#---Step 5: define the size, speed and location of three kinds of stars and store them in their respective lists---  
#---Pay attention to 200 and quit for drawing 200 planets. Too many of them are stuck---  
for i in range(200):  
    star = t.clone()  
    #Determine the size of the planet  
    s= random()/3  
    star.shapesize(s,s)  
    star.speed(int(s*10))  
    #Randomly generated coordinates  
    star.setx(width/2 + randint(1,width))  
    star.sety(randint(-height/2,height/2))  
    star.showturtle()  
    stars.append(star)  
  
for i in range(200):  
    star2 = t2.clone()  
    #Determine the size of the planet  
    s2= random()/2  
    star2.shapesize(s2,s2)  
    star2.speed(int(s*10))  
    star2.setx(width/2 + randint(1,width))  
    star2.sety(randint(-height/2,height/2))  
    star2.showturtle()  
    stars2.append(star2)  
  
for i in range(200):  
    star3 = t3.clone()  
    #Determine the size of the planet  
    s3= random()*5  
    star3.shapesize(10*s3,10*s3)  
    star3.speed(int(s3*10))  
    star3.setx(width*2 + randint(1,width))  
    star3.sety(randint(-height*2,height*2))  
    star3.showturtle()  
    stars3.append(star3)

8. sixth steps:

#---Step 6 - game cycle - start of each planet  
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()  
  
    for star2 in stars2:  
        star2.setx(star2.xcor() - 3 * star2.speed())  
        if star2.xcor()<-width/2:  
            star2.hideturtle()  
            star2.setx(width/2 + randint(1,width))  
            star2.sety( randint(-height/2,height*2))  
            star2.showturtle()  
  
    for star3 in stars3:  
        star3.setx(star3.xcor() - 3 * star3.speed())  
        if star3.xcor()<-width*2:  
            star3.hideturtle()  
            star3.setx(width*2 + randint(1,width))  
            star3.sety( randint(-height*2,height*2))  
            star3.showturtle()

9. effect picture

This article refers to the original- http://bjbsair.com/2020-03-25/tech-info/6248/ 1. universe

2. Code implementation conditions

python3

3. first steps:

#---Step 1 - import module---  
from turtle import *  
from random import random,randint

4. second steps:

#---Step 2 - initialization definition---  
#---Define screen, window size, title, background color  
screen = Screen()  
#---Bigger, better---  
width ,height = 1600,1200  
screen.setup(width,height)  
screen.title('Romantic starry sky')  
screen.bgcolor("black")  
#Sets or returns the drawing delay in milliseconds, the greater the delay, the slower the drawing  
screen.delay(0)

5. third steps:

#---Step 3: define three different colors of stars with different sizes, speeds, positions and shapes---  
#shape(): set the shape of the tortoise. The values are: "arrow", "turn", "circle", "square", "triangle", "classic"  
#---Stars - white stars---  
t = Turtle(visible = False,shape='circle')  
t.pencolor("white")  
#The color of a turtle, the color of a flying planet  
t.fillcolor("blue")  
t.penup()  
#Rotation angle  
t.setheading(-10)  
#Coordinates are random  
t.goto(width/2,randint(-height/2,height/2))  
  
#---Star 2 - little green star in the distance---  
t2 = Turtle(visible = False,shape='turtle')  
#The color of a turtle, the color of a flying planet  
t2.fillcolor("green")  
t2.penup()  
t2.setheading(-50)  
#Coordinates are random  
t2.goto(width,randint(-height,height))  
  
#---Star 3 - near Red Star---  
t3 = Turtle(visible = False,shape='circle')  
#The color of a turtle, the color of a flying planet  
t3.fillcolor("red")  
t3.penup()  
t3.setheading(-90)  
#Coordinates are random  
t3.goto(width*2,randint(-height*2,height*2))

6. fourth steps:

#---Step 4 - define planet list - for storage---  
stars = []  
stars2 = []  
stars3 = []

7. fifth steps:

#---Step 5: define the size, speed and location of three kinds of stars and store them in their respective lists---  
#---Pay attention to 200 and quit for drawing 200 planets. Too many of them are stuck---  
for i in range(200):  
    star = t.clone()  
    #Determine the size of the planet  
    s= random()/3  
    star.shapesize(s,s)  
    star.speed(int(s*10))  
    #Randomly generated coordinates  
    star.setx(width/2 + randint(1,width))  
    star.sety(randint(-height/2,height/2))  
    star.showturtle()  
    stars.append(star)  
  
for i in range(200):  
    star2 = t2.clone()  
    #Determine the size of the planet  
    s2= random()/2  
    star2.shapesize(s2,s2)  
    star2.speed(int(s*10))  
    star2.setx(width/2 + randint(1,width))  
    star2.sety(randint(-height/2,height/2))  
    star2.showturtle()  
    stars2.append(star2)  
  
for i in range(200):  
    star3 = t3.clone()  
    #Determine the size of the planet  
    s3= random()*5  
    star3.shapesize(10*s3,10*s3)  
    star3.speed(int(s3*10))  
    star3.setx(width*2 + randint(1,width))  
    star3.sety(randint(-height*2,height*2))  
    star3.showturtle()  
    stars3.append(star3)

8. sixth steps:

#---Step 6 - game cycle - start of each planet  
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()  
  
    for star2 in stars2:  
        star2.setx(star2.xcor() - 3 * star2.speed())  
        if star2.xcor()<-width/2:  
            star2.hideturtle()  
            star2.setx(width/2 + randint(1,width))  
            star2.sety( randint(-height/2,height*2))  
            star2.showturtle()  
  
    for star3 in stars3:  
        star3.setx(star3.xcor() - 3 * star3.speed())  
        if star3.xcor()<-width*2:  
            star3.hideturtle()  
            star3.setx(width*2 + randint(1,width))  
            star3.sety( randint(-height*2,height*2))  
            star3.showturtle()

9. effect picture

This article refers to the original- http://bjbsair.com/2020-03-25/tech-info/6248/ 1. universe

2. Code implementation conditions

python3

3. first steps:

#---Step 1 - import module---  
from turtle import *  
from random import random,randint

4. second steps:

#---Step 2 - initialization definition---  
#---Define screen, window size, title, background color  
screen = Screen()  
#---Bigger, better---  
width ,height = 1600,1200  
screen.setup(width,height)  
screen.title('Romantic starry sky')  
screen.bgcolor("black")  
#Sets or returns the drawing delay in milliseconds, the greater the delay, the slower the drawing  
screen.delay(0)

5. third steps:

#---Step 3: define three different colors of stars with different sizes, speeds, positions and shapes---  
#shape(): set the shape of the tortoise. The values are: "arrow", "turn", "circle", "square", "triangle", "classic"  
#---Stars - white stars---  
t = Turtle(visible = False,shape='circle')  
t.pencolor("white")  
#The color of a turtle, the color of a flying planet  
t.fillcolor("blue")  
t.penup()  
#Rotation angle  
t.setheading(-10)  
#Coordinates are random  
t.goto(width/2,randint(-height/2,height/2))  
  
#---Star 2 - little green star in the distance---  
t2 = Turtle(visible = False,shape='turtle')  
#The color of a turtle, the color of a flying planet  
t2.fillcolor("green")  
t2.penup()  
t2.setheading(-50)  
#Coordinates are random  
t2.goto(width,randint(-height,height))  
  
#---Star 3 - near Red Star---  
t3 = Turtle(visible = False,shape='circle')  
#The color of a turtle, the color of a flying planet  
t3.fillcolor("red")  
t3.penup()  
t3.setheading(-90)  
#Coordinates are random  
t3.goto(width*2,randint(-height*2,height*2))

6. fourth steps:

#---Step 4 - define planet list - for storage---  
stars = []  
stars2 = []  
stars3 = []

7. fifth steps:

#---Step 5: define the size, speed and location of three kinds of stars and store them in their respective lists---  
#---Pay attention to 200 and quit for drawing 200 planets. Too many of them are stuck---  
for i in range(200):  
    star = t.clone()  
    #Determine the size of the planet  
    s= random()/3  
    star.shapesize(s,s)  
    star.speed(int(s*10))  
    #Randomly generated coordinates  
    star.setx(width/2 + randint(1,width))  
    star.sety(randint(-height/2,height/2))  
    star.showturtle()  
    stars.append(star)  
  
for i in range(200):  
    star2 = t2.clone()  
    #Determine the size of the planet  
    s2= random()/2  
    star2.shapesize(s2,s2)  
    star2.speed(int(s*10))  
    star2.setx(width/2 + randint(1,width))  
    star2.sety(randint(-height/2,height/2))  
    star2.showturtle()  
    stars2.append(star2)  
  
for i in range(200):  
    star3 = t3.clone()  
    #Determine the size of the planet  
    s3= random()*5  
    star3.shapesize(10*s3,10*s3)  
    star3.speed(int(s3*10))  
    star3.setx(width*2 + randint(1,width))  
    star3.sety(randint(-height*2,height*2))  
    star3.showturtle()  
    stars3.append(star3)

8. sixth steps:

#---Step 6 - game cycle - start of each planet  
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()  
  
    for star2 in stars2:  
        star2.setx(star2.xcor() - 3 * star2.speed())  
        if star2.xcor()<-width/2:  
            star2.hideturtle()  
            star2.setx(width/2 + randint(1,width))  
            star2.sety( randint(-height/2,height*2))  
            star2.showturtle()  
  
    for star3 in stars3:  
        star3.setx(star3.xcor() - 3 * star3.speed())  
        if star3.xcor()<-width*2:  
            star3.hideturtle()  
            star3.setx(width*2 + randint(1,width))  
            star3.sety( randint(-height*2,height*2))  
            star3.showturtle()

9. effect picture

This article refers to the original- http://bjbsair.com/2020-03-25/tech-info/6248/ 1. universe

2. Code implementation conditions

python3

3. first steps:

#---Step 1 - import module---  
from turtle import *  
from random import random,randint

4. second steps:

#---Step 2 - initialization definition---  
#---Define screen, window size, title, background color  
screen = Screen()  
#---Bigger, better---  
width ,height = 1600,1200  
screen.setup(width,height)  
screen.title('Romantic starry sky')  
screen.bgcolor("black")  
#Sets or returns the drawing delay in milliseconds, the greater the delay, the slower the drawing  
screen.delay(0)

5. third steps:

#---Step 3: define three different colors of stars with different sizes, speeds, positions and shapes---  
#shape(): set the shape of the tortoise. The values are: "arrow", "turn", "circle", "square", "triangle", "classic"  
#---Stars - white stars---  
t = Turtle(visible = False,shape='circle')  
t.pencolor("white")  
#The color of a turtle, the color of a flying planet  
t.fillcolor("blue")  
t.penup()  
#Rotation angle  
t.setheading(-10)  
#Coordinates are random  
t.goto(width/2,randint(-height/2,height/2))  
  
#---Star 2 - little green star in the distance---  
t2 = Turtle(visible = False,shape='turtle')  
#The color of a turtle, the color of a flying planet  
t2.fillcolor("green")  
t2.penup()  
t2.setheading(-50)  
#Coordinates are random  
t2.goto(width,randint(-height,height))  
  
#---Star 3 - near Red Star---  
t3 = Turtle(visible = False,shape='circle')  
#The color of a turtle, the color of a flying planet  
t3.fillcolor("red")  
t3.penup()  
t3.setheading(-90)  
#Coordinates are random  
t3.goto(width*2,randint(-height*2,height*2))

6. fourth steps:

#---Step 4 - define planet list - for storage---  
stars = []  
stars2 = []  
stars3 = []

7. fifth steps:

#---Step 5: define the size, speed and location of three kinds of stars and store them in their respective lists---  
#---Pay attention to 200 and quit for drawing 200 planets. Too many of them are stuck---  
for i in range(200):  
    star = t.clone()  
    #Determine the size of the planet  
    s= random()/3  
    star.shapesize(s,s)  
    star.speed(int(s*10))  
    #Randomly generated coordinates  
    star.setx(width/2 + randint(1,width))  
    star.sety(randint(-height/2,height/2))  
    star.showturtle()  
    stars.append(star)  
  
for i in range(200):  
    star2 = t2.clone()  
    #Determine the size of the planet  
    s2= random()/2  
    star2.shapesize(s2,s2)  
    star2.speed(int(s*10))  
    star2.setx(width/2 + randint(1,width))  
    star2.sety(randint(-height/2,height/2))  
    star2.showturtle()  
    stars2.append(star2)  
  
for i in range(200):  
    star3 = t3.clone()  
    #Determine the size of the planet  
    s3= random()*5  
    star3.shapesize(10*s3,10*s3)  
    star3.speed(int(s3*10))  
    star3.setx(width*2 + randint(1,width))  
    star3.sety(randint(-height*2,height*2))  
    star3.showturtle()  
    stars3.append(star3)

8. sixth steps:

#---Step 6 - game cycle - start of each planet  
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()  
  
    for star2 in stars2:  
        star2.setx(star2.xcor() - 3 * star2.speed())  
        if star2.xcor()<-width/2:  
            star2.hideturtle()  
            star2.setx(width/2 + randint(1,width))  
            star2.sety( randint(-height/2,height*2))  
            star2.showturtle()  
  
    for star3 in stars3:  
        star3.setx(star3.xcor() - 3 * star3.speed())  
        if star3.xcor()<-width*2:  
            star3.hideturtle()  
            star3.setx(width*2 + randint(1,width))  
            star3.sety( randint(-height*2,height*2))  
            star3.showturtle()

9. effect picture

This article refers to the original- http://bjbsair.com/2020-03-25/tech-info/6248/ 1. universe

2. Code implementation conditions

python3

3. first steps:

#---Step 1 - import module---  
from turtle import *  
from random import random,randint

4. second steps:

#---Step 2 - initialization definition---  
#---Define screen, window size, title, background color  
screen = Screen()  
#---Bigger, better---  
width ,height = 1600,1200  
screen.setup(width,height)  
screen.title('Romantic starry sky')  
screen.bgcolor("black")  
#Sets or returns the drawing delay in milliseconds, the greater the delay, the slower the drawing  
screen.delay(0)

5. third steps:

#---Step 3: define three different colors of stars with different sizes, speeds, positions and shapes---  
#shape(): set the shape of the tortoise. The values are: "arrow", "turn", "circle", "square", "triangle", "classic"  
#---Stars - white stars---  
t = Turtle(visible = False,shape='circle')  
t.pencolor("white")  
#The color of a turtle, the color of a flying planet  
t.fillcolor("blue")  
t.penup()  
#Rotation angle  
t.setheading(-10)  
#Coordinates are random  
t.goto(width/2,randint(-height/2,height/2))  
  
#---Star 2 - little green star in the distance---  
t2 = Turtle(visible = False,shape='turtle')  
#The color of a turtle, the color of a flying planet  
t2.fillcolor("green")  
t2.penup()  
t2.setheading(-50)  
#Coordinates are random  
t2.goto(width,randint(-height,height))  
  
#---Star 3 - near Red Star---  
t3 = Turtle(visible = False,shape='circle')  
#The color of a turtle, the color of a flying planet  
t3.fillcolor("red")  
t3.penup()  
t3.setheading(-90)  
#Coordinates are random  
t3.goto(width*2,randint(-height*2,height*2))

6. fourth steps:

#---Step 4 - define planet list - for storage---  
stars = []  
stars2 = []  
stars3 = []

7. fifth steps:

#---Step 5: define the size, speed and location of three kinds of stars and store them in their respective lists---  
#---Pay attention to 200 and quit for drawing 200 planets. Too many of them are stuck---  
for i in range(200):  
    star = t.clone()  
    #Determine the size of the planet  
    s= random()/3  
    star.shapesize(s,s)  
    star.speed(int(s*10))  
    #Randomly generated coordinates  
    star.setx(width/2 + randint(1,width))  
    star.sety(randint(-height/2,height/2))  
    star.showturtle()  
    stars.append(star)  
  
for i in range(200):  
    star2 = t2.clone()  
    #Determine the size of the planet  
    s2= random()/2  
    star2.shapesize(s2,s2)  
    star2.speed(int(s*10))  
    star2.setx(width/2 + randint(1,width))  
    star2.sety(randint(-height/2,height/2))  
    star2.showturtle()  
    stars2.append(star2)  
  
for i in range(200):  
    star3 = t3.clone()  
    #Determine the size of the planet  
    s3= random()*5  
    star3.shapesize(10*s3,10*s3)  
    star3.speed(int(s3*10))  
    star3.setx(width*2 + randint(1,width))  
    star3.sety(randint(-height*2,height*2))  
    star3.showturtle()  
    stars3.append(star3)

8. sixth steps:

#---Step 6 - game cycle - start of each planet  
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()  
  
    for star2 in stars2:  
        star2.setx(star2.xcor() - 3 * star2.speed())  
        if star2.xcor()<-width/2:  
            star2.hideturtle()  
            star2.setx(width/2 + randint(1,width))  
            star2.sety( randint(-height/2,height*2))  
            star2.showturtle()  
  
    for star3 in stars3:  
        star3.setx(star3.xcor() - 3 * star3.speed())  
        if star3.xcor()<-width*2:  
            star3.hideturtle()  
            star3.setx(width*2 + randint(1,width))  
            star3.sety( randint(-height*2,height*2))  
            star3.showturtle()

9. effect picture

This article refers to the original- http://bjbsair.com/2020-03-25/tech-info/6248/ 1. universe

2. Code implementation conditions

python3

3. first steps:

#---Step 1 - import module---  
from turtle import *  
from random import random,randint

4. second steps:

#---Step 2 - initialization definition---  
#---Define screen, window size, title, background color  
screen = Screen()  
#---Bigger, better---  
width ,height = 1600,1200  
screen.setup(width,height)  
screen.title('Romantic starry sky')  
screen.bgcolor("black")  
#Sets or returns the drawing delay in milliseconds, the greater the delay, the slower the drawing  
screen.delay(0)

5. third steps:

#---Step 3: define three different colors of stars with different sizes, speeds, positions and shapes---  
#shape(): set the shape of the tortoise. The values are: "arrow", "turn", "circle", "square", "triangle", "classic"  
#---Stars - white stars---  
t = Turtle(visible = False,shape='circle')  
t.pencolor("white")  
#The color of a turtle, the color of a flying planet  
t.fillcolor("blue")  
t.penup()  
#Rotation angle  
t.setheading(-10)  
#Coordinates are random  
t.goto(width/2,randint(-height/2,height/2))  
  
#---Star 2 - little green star in the distance---  
t2 = Turtle(visible = False,shape='turtle')  
#The color of a turtle, the color of a flying planet  
t2.fillcolor("green")  
t2.penup()  
t2.setheading(-50)  
#Coordinates are random  
t2.goto(width,randint(-height,height))  
  
#---Star 3 - near Red Star---  
t3 = Turtle(visible = False,shape='circle')  
#The color of a turtle, the color of a flying planet  
t3.fillcolor("red")  
t3.penup()  
t3.setheading(-90)  
#Coordinates are random  
t3.goto(width*2,randint(-height*2,height*2))

6. fourth steps:

#---Step 4 - define planet list - for storage---  
stars = []  
stars2 = []  
stars3 = []

7. fifth steps:

#---Step 5: define the size, speed and location of three kinds of stars and store them in their respective lists---  
#---Pay attention to 200 and quit for drawing 200 planets. Too many of them are stuck---  
for i in range(200):  
    star = t.clone()  
    #Determine the size of the planet  
    s= random()/3  
    star.shapesize(s,s)  
    star.speed(int(s*10))  
    #Randomly generated coordinates  
    star.setx(width/2 + randint(1,width))  
    star.sety(randint(-height/2,height/2))  
    star.showturtle()  
    stars.append(star)  
  
for i in range(200):  
    star2 = t2.clone()  
    #Determine the size of the planet  
    s2= random()/2  
    star2.shapesize(s2,s2)  
    star2.speed(int(s*10))  
    star2.setx(width/2 + randint(1,width))  
    star2.sety(randint(-height/2,height/2))  
    star2.showturtle()  
    stars2.append(star2)  
  
for i in range(200):  
    star3 = t3.clone()  
    #Determine the size of the planet  
    s3= random()*5  
    star3.shapesize(10*s3,10*s3)  
    star3.speed(int(s3*10))  
    star3.setx(width*2 + randint(1,width))  
    star3.sety(randint(-height*2,height*2))  
    star3.showturtle()  
    stars3.append(star3)

8. sixth steps:

#---Step 6 - game cycle - start of each planet  
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()  
  
    for star2 in stars2:  
        star2.setx(star2.xcor() - 3 * star2.speed())  
        if star2.xcor()<-width/2:  
            star2.hideturtle()  
            star2.setx(width/2 + randint(1,width))  
            star2.sety( randint(-height/2,height*2))  
            star2.showturtle()  
  
    for star3 in stars3:  
        star3.setx(star3.xcor() - 3 * star3.speed())  
        if star3.xcor()<-width*2:  
            star3.hideturtle()  
            star3.setx(width*2 + randint(1,width))  
            star3.sety( randint(-height*2,height*2))  
            star3.showturtle()

9. effect picture

This article refers to the original- http://bjbsair.com/2020-03-25/tech-info/6248/ 1. universe

2. Code implementation conditions

python3

3. first steps:

#---Step 1 - import module---  
from turtle import *  
from random import random,randint

4. second steps:

#---Step 2 - initialization definition---  
#---Define screen, window size, title, background color  
screen = Screen()  
#---Bigger, better---  
width ,height = 1600,1200  
screen.setup(width,height)  
screen.title('Romantic starry sky')  
screen.bgcolor("black")  
#Sets or returns the drawing delay in milliseconds, the greater the delay, the slower the drawing  
screen.delay(0)

5. third steps:

#---Step 3: define three different colors of stars with different sizes, speeds, positions and shapes---  
#shape(): set the shape of the tortoise. The values are: "arrow", "turn", "circle", "square", "triangle", "classic"  
#---Stars - white stars---  
t = Turtle(visible = False,shape='circle')  
t.pencolor("white")  
#The color of a turtle, the color of a flying planet  
t.fillcolor("blue")  
t.penup()  
#Rotation angle  
t.setheading(-10)  
#Coordinates are random  
t.goto(width/2,randint(-height/2,height/2))  
  
#---Star 2 - little green star in the distance---  
t2 = Turtle(visible = False,shape='turtle')  
#The color of a turtle, the color of a flying planet  
t2.fillcolor("green")  
t2.penup()  
t2.setheading(-50)  
#Coordinates are random  
t2.goto(width,randint(-height,height))  
  
#---Star 3 - near Red Star---  
t3 = Turtle(visible = False,shape='circle')  
#The color of a turtle, the color of a flying planet  
t3.fillcolor("red")  
t3.penup()  
t3.setheading(-90)  
#Coordinates are random  
t3.goto(width*2,randint(-height*2,height*2))

6. fourth steps:

#---Step 4 - define planet list - for storage---  
stars = []  
stars2 = []  
stars3 = []

7. fifth steps:

#---Step 5: define the size, speed and location of three kinds of stars and store them in their respective lists---  
#---Pay attention to 200 and quit for drawing 200 planets. Too many of them are stuck---  
for i in range(200):  
    star = t.clone()  
    #Determine the size of the planet  
    s= random()/3  
    star.shapesize(s,s)  
    star.speed(int(s*10))  
    #Randomly generated coordinates  
    star.setx(width/2 + randint(1,width))  
    star.sety(randint(-height/2,height/2))  
    star.showturtle()  
    stars.append(star)  
  
for i in range(200):  
    star2 = t2.clone()  
    #Determine the size of the planet  
    s2= random()/2  
    star2.shapesize(s2,s2)  
    star2.speed(int(s*10))  
    star2.setx(width/2 + randint(1,width))  
    star2.sety(randint(-height/2,height/2))  
    star2.showturtle()  
    stars2.append(star2)  
  
for i in range(200):  
    star3 = t3.clone()  
    #Determine the size of the planet  
    s3= random()*5  
    star3.shapesize(10*s3,10*s3)  
    star3.speed(int(s3*10))  
    star3.setx(width*2 + randint(1,width))  
    star3.sety(randint(-height*2,height*2))  
    star3.showturtle()  
    stars3.append(star3)

8. sixth steps:

#---Step 6 - game cycle - start of each planet  
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()  
  
    for star2 in stars2:  
        star2.setx(star2.xcor() - 3 * star2.speed())  
        if star2.xcor()<-width/2:  
            star2.hideturtle()  
            star2.setx(width/2 + randint(1,width))  
            star2.sety( randint(-height/2,height*2))  
            star2.showturtle()  
  
    for star3 in stars3:  
        star3.setx(star3.xcor() - 3 * star3.speed())  
        if star3.xcor()<-width*2:  
            star3.hideturtle()  
            star3.setx(width*2 + randint(1,width))  
            star3.sety( randint(-height*2,height*2))  
            star3.showturtle()

9. effect picture

This article refers to the original- http://bjbsair.com/2020-03-25/tech-info/6248/ 1. universe

2. Code implementation conditions

python3

3. first steps:

#---Step 1 - import module---  
from turtle import *  
from random import random,randint

4. second steps:

#---Step 2 - initialization definition---  
#---Define screen, window size, title, background color  
screen = Screen()  
#---Bigger, better---  
width ,height = 1600,1200  
screen.setup(width,height)  
screen.title('Romantic starry sky')  
screen.bgcolor("black")  
#Sets or returns the drawing delay in milliseconds, the greater the delay, the slower the drawing  
screen.delay(0)

5. third steps:

#---Step 3: define three different colors of stars with different sizes, speeds, positions and shapes---  
#shape(): set the shape of the tortoise. The values are: "arrow", "turn", "circle", "square", "triangle", "classic"  
#---Stars - white stars---  
t = Turtle(visible = False,shape='circle')  
t.pencolor("white")  
#The color of a turtle, the color of a flying planet  
t.fillcolor("blue")  
t.penup()  
#Rotation angle  
t.setheading(-10)  
#Coordinates are random  
t.goto(width/2,randint(-height/2,height/2))  
  
#---Star 2 - little green star in the distance---  
t2 = Turtle(visible = False,shape='turtle')  
#The color of a turtle, the color of a flying planet  
t2.fillcolor("green")  
t2.penup()  
t2.setheading(-50)  
#Coordinates are random  
t2.goto(width,randint(-height,height))  
  
#---Star 3 - near Red Star---  
t3 = Turtle(visible = False,shape='circle')  
#The color of a turtle, the color of a flying planet  
t3.fillcolor("red")  
t3.penup()  
t3.setheading(-90)  
#Coordinates are random  
t3.goto(width*2,randint(-height*2,height*2))

6. fourth steps:

#---Step 4 - define planet list - for storage---  
stars = []  
stars2 = []  
stars3 = []

7. fifth steps:

#---Step 5: define the size, speed and location of three kinds of stars and store them in their respective lists---  
#---Pay attention to 200 and quit for drawing 200 planets. Too many of them are stuck---  
for i in range(200):  
    star = t.clone()  
    #Determine the size of the planet  
    s= random()/3  
    star.shapesize(s,s)  
    star.speed(int(s*10))  
    #Randomly generated coordinates  
    star.setx(width/2 + randint(1,width))  
    star.sety(randint(-height/2,height/2))  
    star.showturtle()  
    stars.append(star)  
  
for i in range(200):  
    star2 = t2.clone()  
    #Determine the size of the planet  
    s2= random()/2  
    star2.shapesize(s2,s2)  
    star2.speed(int(s*10))  
    star2.setx(width/2 + randint(1,width))  
    star2.sety(randint(-height/2,height/2))  
    star2.showturtle()  
    stars2.append(star2)  
  
for i in range(200):  
    star3 = t3.clone()  
    #Determine the size of the planet  
    s3= random()*5  
    star3.shapesize(10*s3,10*s3)  
    star3.speed(int(s3*10))  
    star3.setx(width*2 + randint(1,width))  
    star3.sety(randint(-height*2,height*2))  
    star3.showturtle()  
    stars3.append(star3)

8. sixth steps:

#---Step 6 - game cycle - start of each planet  
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()  
  
    for star2 in stars2:  
        star2.setx(star2.xcor() - 3 * star2.speed())  
        if star2.xcor()<-width/2:  
            star2.hideturtle()  
            star2.setx(width/2 + randint(1,width))  
            star2.sety( randint(-height/2,height*2))  
            star2.showturtle()  
  
    for star3 in stars3:  
        star3.setx(star3.xcor() - 3 * star3.speed())  
        if star3.xcor()<-width*2:  
            star3.hideturtle()  
            star3.setx(width*2 + randint(1,width))  
            star3.sety( randint(-height*2,height*2))  
            star3.showturtle()

9. effect picture

This article refers to the original- http://bjbsair.com/2020-03-25/tech-info/6248/ 1. universe

2. Code implementation conditions

python3

3. first steps:

#---Step 1 - import module---  
from turtle import *  
from random import random,randint

4. second steps:

#---Step 2 - initialization definition---  
#---Define screen, window size, title, background color  
screen = Screen()  
#---Bigger, better---  
width ,height = 1600,1200  
screen.setup(width,height)  
screen.title('Romantic starry sky')  
screen.bgcolor("black")  
#Sets or returns the drawing delay in milliseconds, the greater the delay, the slower the drawing  
screen.delay(0)

5. third steps:

#---Step 3: define three different colors of stars with different sizes, speeds, positions and shapes---  
#shape(): set the shape of the tortoise. The values are: "arrow", "turn", "circle", "square", "triangle", "classic"  
#---Stars - white stars---  
t = Turtle(visible = False,shape='circle')  
t.pencolor("white")  
#The color of a turtle, the color of a flying planet  
t.fillcolor("blue")  
t.penup()  
#Rotation angle  
t.setheading(-10)  
#Coordinates are random  
t.goto(width/2,randint(-height/2,height/2))  
  
#---Star 2 - little green star in the distance---  
t2 = Turtle(visible = False,shape='turtle')  
#The color of a turtle, the color of a flying planet  
t2.fillcolor("green")  
t2.penup()  
t2.setheading(-50)  
#Coordinates are random  
t2.goto(width,randint(-height,height))  
  
#---Star 3 - near Red Star---  
t3 = Turtle(visible = False,shape='circle')  
#The color of a turtle, the color of a flying planet  
t3.fillcolor("red")  
t3.penup()  
t3.setheading(-90)  
#Coordinates are random  
t3.goto(width*2,randint(-height*2,height*2))

6. fourth steps:

#---Step 4 - define planet list - for storage---  
stars = []  
stars2 = []  
stars3 = []

7. fifth steps:

#---Step 5: define the size, speed and location of three kinds of stars and store them in their respective lists---  
#---Pay attention to 200 and quit for drawing 200 planets. Too many of them are stuck---  
for i in range(200):  
    star = t.clone()  
    #Determine the size of the planet  
    s= random()/3  
    star.shapesize(s,s)  
    star.speed(int(s*10))  
    #Randomly generated coordinates  
    star.setx(width/2 + randint(1,width))  
    star.sety(randint(-height/2,height/2))  
    star.showturtle()  
    stars.append(star)  
  
for i in range(200):  
    star2 = t2.clone()  
    #Determine the size of the planet  
    s2= random()/2  
    star2.shapesize(s2,s2)  
    star2.speed(int(s*10))  
    star2.setx(width/2 + randint(1,width))  
    star2.sety(randint(-height/2,height/2))  
    star2.showturtle()  
    stars2.append(star2)  
  
for i in range(200):  
    star3 = t3.clone()  
    #Determine the size of the planet  
    s3= random()*5  
    star3.shapesize(10*s3,10*s3)  
    star3.speed(int(s3*10))  
    star3.setx(width*2 + randint(1,width))  
    star3.sety(randint(-height*2,height*2))  
    star3.showturtle()  
    stars3.append(star3)

8. sixth steps:

#---Step 6 - game cycle - start of each planet  
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()  
  
    for star2 in stars2:  
        star2.setx(star2.xcor() - 3 * star2.speed())  
        if star2.xcor()<-width/2:  
            star2.hideturtle()  
            star2.setx(width/2 + randint(1,width))  
            star2.sety( randint(-height/2,height*2))  
            star2.showturtle()  
  
    for star3 in stars3:  
        star3.setx(star3.xcor() - 3 * star3.speed())  
        if star3.xcor()<-width*2:  
            star3.hideturtle()  
            star3.setx(width*2 + randint(1,width))  
            star3.sety( randint(-height*2,height*2))  
            star3.showturtle()

9. effect picture

Tags: Programming

Posted on Thu, 26 Mar 2020 10:31:04 -0400 by Brendan Nolan