This article is referred to -bjbsair.com/2020-03-25/… 1. The universe

2. Code implementation conditions

python3

Step 1:

#-- Step 1 -- Import module --
from turtle import *  
from random import random,randint
Copy the code

4. Step 2:

Step 2: Initialize the definition
Define screen, window size, title, background color
screen = Screen()  
#-- A little bigger effect is better --Setup (width,height) screen.title(Sky of Romance)  
screen.bgcolor("black")  
# Set or return the drawing delay in milliseconds, the larger the delay, the slower the drawing
screen.delay(0)
Copy the code

5. Step 3:

Step 3: define 3 different colors of planets with different sizes, velocities, positions and shapes
#shape(): Sets the shape of the turtle. Values: "arrow", "Turtle", "Circle", "square", "triangle", "classic"
#-- Planet -- white star --
t = Turtle(visible = False,shape='circle')  
t.pencolor("white")  
The color of the turtle is the color of the flying planet
t.fillcolor("blue")  
t.penup()  
# Rotation Angle
t.setheading(-10)  
# Coordinates are random
t.goto(width/2,randint(-height/2,height/2))  
  
#-- Planet 2-- little green distant star --
t2 = Turtle(visible = False,shape='turtle')  
The color of the turtle is the color of the flying planet
t2.fillcolor("green")  
t2.penup()  
t2.setheading(-50)  
# Coordinates are random
t2.goto(width,randint(-height,height))  
  
#-- Planet 3-- near red star --
t3 = Turtle(visible = False,shape='circle')  
The color of the turtle is the color of the flying planet
t3.fillcolor("red")  
t3.penup()  
t3.setheading(-90)  
# Coordinates are random
t3.goto(width*2,randint(-height*2,height*2))
Copy the code

5. 6. Smart refrigerator

#-- Step 4 -- define the list of planets for storage
stars = []  
stars2 = []  
stars3 = []
Copy the code

7. Step 5:

Step 5: define the size, speed and position of the three planets and store them in their respective lists
#-- note that 200 is to draw 200 respective planets quit, note too much to be 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))  
    # Generate coordinates randomly
    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 planetS3 = 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)Copy the code

8. Step 6:

#-- Step 6 -- game loop -- start your 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()
Copy the code

9. Rendering

Bjbsair.com/2020-03-25/…

2. Code implementation conditions

python3

Step 1:

#-- Step 1 -- Import module --
from turtle import *  
from random import random,randint
Copy the code

4. Step 2:

Step 2: Initialize the definition
Define screen, window size, title, background color
screen = Screen()  
#-- A little bigger effect is better --Setup (width,height) screen.title(Sky of Romance)  
screen.bgcolor("black")  
# Set or return the drawing delay in milliseconds, the larger the delay, the slower the drawing
screen.delay(0)
Copy the code

5. Step 3:

Step 3: define 3 different colors of planets with different sizes, velocities, positions and shapes
#shape(): Sets the shape of the turtle. Values: "arrow", "Turtle", "Circle", "square", "triangle", "classic"
#-- Planet -- white star --
t = Turtle(visible = False,shape='circle')  
t.pencolor("white")  
The color of the turtle is the color of the flying planet
t.fillcolor("blue")  
t.penup()  
# Rotation Angle
t.setheading(-10)  
# Coordinates are random
t.goto(width/2,randint(-height/2,height/2))  
  
#-- Planet 2-- little green distant star --
t2 = Turtle(visible = False,shape='turtle')  
The color of the turtle is the color of the flying planet
t2.fillcolor("green")  
t2.penup()  
t2.setheading(-50)  
# Coordinates are random
t2.goto(width,randint(-height,height))  
  
#-- Planet 3-- near red star --
t3 = Turtle(visible = False,shape='circle')  
The color of the turtle is the color of the flying planet
t3.fillcolor("red")  
t3.penup()  
t3.setheading(-90)  
# Coordinates are random
t3.goto(width*2,randint(-height*2,height*2))
Copy the code

5. 6. Smart refrigerator

#-- Step 4 -- define the list of planets for storage
stars = []  
stars2 = []  
stars3 = []
Copy the code

7. Step 5:

Step 5: define the size, speed and position of the three planets and store them in their respective lists
#-- note that 200 is to draw 200 respective planets quit, note too much to be 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))  
    # Generate coordinates randomly
    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 planetS3 = 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)Copy the code

8. Step 6:

#-- Step 6 -- game loop -- start your 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()
Copy the code

9. Rendering

Bjbsair.com/2020-03-25/…

2. Code implementation conditions

python3

Step 1:

#-- Step 1 -- Import module --
from turtle import *  
from random import random,randint
Copy the code

4. Step 2:

Step 2: Initialize the definition
Define screen, window size, title, background color
screen = Screen()  
#-- A little bigger effect is better --Setup (width,height) screen.title(Sky of Romance)  
screen.bgcolor("black")  
# Set or return the drawing delay in milliseconds, the larger the delay, the slower the drawing
screen.delay(0)
Copy the code

5. Step 3:

Step 3: define 3 different colors of planets with different sizes, velocities, positions and shapes
#shape(): Sets the shape of the turtle. Values: "arrow", "Turtle", "Circle", "square", "triangle", "classic"
#-- Planet -- white star --
t = Turtle(visible = False,shape='circle')  
t.pencolor("white")  
The color of the turtle is the color of the flying planet
t.fillcolor("blue")  
t.penup()  
# Rotation Angle
t.setheading(-10)  
# Coordinates are random
t.goto(width/2,randint(-height/2,height/2))  
  
#-- Planet 2-- little green distant star --
t2 = Turtle(visible = False,shape='turtle')  
The color of the turtle is the color of the flying planet
t2.fillcolor("green")  
t2.penup()  
t2.setheading(-50)  
# Coordinates are random
t2.goto(width,randint(-height,height))  
  
#-- Planet 3-- near red star --
t3 = Turtle(visible = False,shape='circle')  
The color of the turtle is the color of the flying planet
t3.fillcolor("red")  
t3.penup()  
t3.setheading(-90)  
# Coordinates are random
t3.goto(width*2,randint(-height*2,height*2))
Copy the code

5. 6. Smart refrigerator

#-- Step 4 -- define the list of planets for storage
stars = []  
stars2 = []  
stars3 = []
Copy the code

7. Step 5:

Step 5: define the size, speed and position of the three planets and store them in their respective lists
#-- note that 200 is to draw 200 respective planets quit, note too much to be 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))  
    # Generate coordinates randomly
    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 planetS3 = 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)Copy the code

8. Step 6:

#-- Step 6 -- game loop -- start your 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()
Copy the code

9. Rendering

Bjbsair.com/2020-03-25/…

2. Code implementation conditions

python3

Step 1:

#-- Step 1 -- Import module --
from turtle import *  
from random import random,randint
Copy the code

4. Step 2:

Step 2: Initialize the definition
Define screen, window size, title, background color
screen = Screen()  
#-- A little bigger effect is better --Setup (width,height) screen.title(Sky of Romance)  
screen.bgcolor("black")  
# Set or return the drawing delay in milliseconds, the larger the delay, the slower the drawing
screen.delay(0)
Copy the code

5. Step 3:

Step 3: define 3 different colors of planets with different sizes, velocities, positions and shapes
#shape(): Sets the shape of the turtle. Values: "arrow", "Turtle", "Circle", "square", "triangle", "classic"
#-- Planet -- white star --
t = Turtle(visible = False,shape='circle')  
t.pencolor("white")  
The color of the turtle is the color of the flying planet
t.fillcolor("blue")  
t.penup()  
# Rotation Angle
t.setheading(-10)  
# Coordinates are random
t.goto(width/2,randint(-height/2,height/2))  
  
#-- Planet 2-- little green distant star --
t2 = Turtle(visible = False,shape='turtle')  
The color of the turtle is the color of the flying planet
t2.fillcolor("green")  
t2.penup()  
t2.setheading(-50)  
# Coordinates are random
t2.goto(width,randint(-height,height))  
  
#-- Planet 3-- near red star --
t3 = Turtle(visible = False,shape='circle')  
The color of the turtle is the color of the flying planet
t3.fillcolor("red")  
t3.penup()  
t3.setheading(-90)  
# Coordinates are random
t3.goto(width*2,randint(-height*2,height*2))
Copy the code

5. 6. Smart refrigerator

#-- Step 4 -- define the list of planets for storage
stars = []  
stars2 = []  
stars3 = []
Copy the code

7. Step 5:

Step 5: define the size, speed and position of the three planets and store them in their respective lists
#-- note that 200 is to draw 200 respective planets quit, note too much to be 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))  
    # Generate coordinates randomly
    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 planetS3 = 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)Copy the code

8. Step 6:

#-- Step 6 -- game loop -- start your 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()
Copy the code

9. Rendering

Bjbsair.com/2020-03-25/…

2. Code implementation conditions

python3

Step 1:

#-- Step 1 -- Import module --
from turtle import *  
from random import random,randint
Copy the code

4. Step 2:

Step 2: Initialize the definition
Define screen, window size, title, background color
screen = Screen()  
#-- A little bigger effect is better --Setup (width,height) screen.title(Sky of Romance)  
screen.bgcolor("black")  
# Set or return the drawing delay in milliseconds, the larger the delay, the slower the drawing
screen.delay(0)
Copy the code

5. Step 3:

Step 3: define 3 different colors of planets with different sizes, velocities, positions and shapes
#shape(): Sets the shape of the turtle. Values: "arrow", "Turtle", "Circle", "square", "triangle", "classic"
#-- Planet -- white star --
t = Turtle(visible = False,shape='circle')  
t.pencolor("white")  
The color of the turtle is the color of the flying planet
t.fillcolor("blue")  
t.penup()  
# Rotation Angle
t.setheading(-10)  
# Coordinates are random
t.goto(width/2,randint(-height/2,height/2))  
  
#-- Planet 2-- little green distant star --
t2 = Turtle(visible = False,shape='turtle')  
The color of the turtle is the color of the flying planet
t2.fillcolor("green")  
t2.penup()  
t2.setheading(-50)  
# Coordinates are random
t2.goto(width,randint(-height,height))  
  
#-- Planet 3-- near red star --
t3 = Turtle(visible = False,shape='circle')  
The color of the turtle is the color of the flying planet
t3.fillcolor("red")  
t3.penup()  
t3.setheading(-90)  
# Coordinates are random
t3.goto(width*2,randint(-height*2,height*2))
Copy the code

5. 6. Smart refrigerator

#-- Step 4 -- define the list of planets for storage
stars = []  
stars2 = []  
stars3 = []
Copy the code

7. Step 5:

Step 5: define the size, speed and position of the three planets and store them in their respective lists
#-- note that 200 is to draw 200 respective planets quit, note too much to be 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))  
    # Generate coordinates randomly
    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 planetS3 = 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)Copy the code

8. Step 6:

#-- Step 6 -- game loop -- start your 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()
Copy the code

9. Rendering

Bjbsair.com/2020-03-25/…

2. Code implementation conditions

python3

Step 1:

#-- Step 1 -- Import module --
from turtle import *  
from random import random,randint
Copy the code

4. Step 2:

Step 2: Initialize the definition
Define screen, window size, title, background color
screen = Screen()  
#-- A little bigger effect is better --Setup (width,height) screen.title(Sky of Romance)  
screen.bgcolor("black")  
# Set or return the drawing delay in milliseconds, the larger the delay, the slower the drawing
screen.delay(0)
Copy the code

5. Step 3:

Step 3: define 3 different colors of planets with different sizes, velocities, positions and shapes
#shape(): Sets the shape of the turtle. Values: "arrow", "Turtle", "Circle", "square", "triangle", "classic"
#-- Planet -- white star --
t = Turtle(visible = False,shape='circle')  
t.pencolor("white")  
The color of the turtle is the color of the flying planet
t.fillcolor("blue")  
t.penup()  
# Rotation Angle
t.setheading(-10)  
# Coordinates are random
t.goto(width/2,randint(-height/2,height/2))  
  
#-- Planet 2-- little green distant star --
t2 = Turtle(visible = False,shape='turtle')  
The color of the turtle is the color of the flying planet
t2.fillcolor("green")  
t2.penup()  
t2.setheading(-50)  
# Coordinates are random
t2.goto(width,randint(-height,height))  
  
#-- Planet 3-- near red star --
t3 = Turtle(visible = False,shape='circle')  
The color of the turtle is the color of the flying planet
t3.fillcolor("red")  
t3.penup()  
t3.setheading(-90)  
# Coordinates are random
t3.goto(width*2,randint(-height*2,height*2))
Copy the code

5. 6. Smart refrigerator

#-- Step 4 -- define the list of planets for storage
stars = []  
stars2 = []  
stars3 = []
Copy the code

7. Step 5:

Step 5: define the size, speed and position of the three planets and store them in their respective lists
#-- note that 200 is to draw 200 respective planets quit, note too much to be 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))  
    # Generate coordinates randomly
    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 planetS3 = 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)Copy the code

8. Step 6:

#-- Step 6 -- game loop -- start your 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()
Copy the code

9. Rendering

Bjbsair.com/2020-03-25/…

2. Code implementation conditions

python3

Step 1:

#-- Step 1 -- Import module --
from turtle import *  
from random import random,randint
Copy the code

4. Step 2:

Step 2: Initialize the definition
Define screen, window size, title, background color
screen = Screen()  
#-- A little bigger effect is better --Setup (width,height) screen.title(Sky of Romance)  
screen.bgcolor("black")  
# Set or return the drawing delay in milliseconds, the larger the delay, the slower the drawing
screen.delay(0)
Copy the code

5. Step 3:

Step 3: define 3 different colors of planets with different sizes, velocities, positions and shapes
#shape(): Sets the shape of the turtle. Values: "arrow", "Turtle", "Circle", "square", "triangle", "classic"
#-- Planet -- white star --
t = Turtle(visible = False,shape='circle')  
t.pencolor("white")  
The color of the turtle is the color of the flying planet
t.fillcolor("blue")  
t.penup()  
# Rotation Angle
t.setheading(-10)  
# Coordinates are random
t.goto(width/2,randint(-height/2,height/2))  
  
#-- Planet 2-- little green distant star --
t2 = Turtle(visible = False,shape='turtle')  
The color of the turtle is the color of the flying planet
t2.fillcolor("green")  
t2.penup()  
t2.setheading(-50)  
# Coordinates are random
t2.goto(width,randint(-height,height))  
  
#-- Planet 3-- near red star --
t3 = Turtle(visible = False,shape='circle')  
The color of the turtle is the color of the flying planet
t3.fillcolor("red")  
t3.penup()  
t3.setheading(-90)  
# Coordinates are random
t3.goto(width*2,randint(-height*2,height*2))
Copy the code

5. 6. Smart refrigerator

#-- Step 4 -- define the list of planets for storage
stars = []  
stars2 = []  
stars3 = []
Copy the code

7. Step 5:

Step 5: define the size, speed and position of the three planets and store them in their respective lists
#-- note that 200 is to draw 200 respective planets quit, note too much to be 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))  
    # Generate coordinates randomly
    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 planetS3 = 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)Copy the code

8. Step 6:

#-- Step 6 -- game loop -- start your 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()
Copy the code

9. Rendering

Bjbsair.com/2020-03-25/…

2. Code implementation conditions

python3

Step 1:

#-- Step 1 -- Import module --
from turtle import *  
from random import random,randint
Copy the code

4. Step 2:

Step 2: Initialize the definition
Define screen, window size, title, background color
screen = Screen()  
#-- A little bigger effect is better --Setup (width,height) screen.title(Sky of Romance)  
screen.bgcolor("black")  
# Set or return the drawing delay in milliseconds, the larger the delay, the slower the drawing
screen.delay(0)
Copy the code

5. Step 3:

Step 3: define 3 different colors of planets with different sizes, velocities, positions and shapes
#shape(): Sets the shape of the turtle. Values: "arrow", "Turtle", "Circle", "square", "triangle", "classic"
#-- Planet -- white star --
t = Turtle(visible = False,shape='circle')  
t.pencolor("white")  
The color of the turtle is the color of the flying planet
t.fillcolor("blue")  
t.penup()  
# Rotation Angle
t.setheading(-10)  
# Coordinates are random
t.goto(width/2,randint(-height/2,height/2))  
  
#-- Planet 2-- little green distant star --
t2 = Turtle(visible = False,shape='turtle')  
The color of the turtle is the color of the flying planet
t2.fillcolor("green")  
t2.penup()  
t2.setheading(-50)  
# Coordinates are random
t2.goto(width,randint(-height,height))  
  
#-- Planet 3-- near red star --
t3 = Turtle(visible = False,shape='circle')  
The color of the turtle is the color of the flying planet
t3.fillcolor("red")  
t3.penup()  
t3.setheading(-90)  
# Coordinates are random
t3.goto(width*2,randint(-height*2,height*2))
Copy the code

5. 6. Smart refrigerator

#-- Step 4 -- define the list of planets for storage
stars = []  
stars2 = []  
stars3 = []
Copy the code

7. Step 5:

Step 5: define the size, speed and position of the three planets and store them in their respective lists
#-- note that 200 is to draw 200 respective planets quit, note too much to be 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))  
    # Generate coordinates randomly
    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 planetS3 = 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)Copy the code

8. Step 6:

#-- Step 6 -- game loop -- start your 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()
Copy the code

9. Rendering

Bjbsair.com/2020-03-25/…

2. Code implementation conditions

python3

Step 1:

#-- Step 1 -- Import module --
from turtle import *  
from random import random,randint
Copy the code

4. Step 2:

Step 2: Initialize the definition
Define screen, window size, title, background color
screen = Screen()  
#-- A little bigger effect is better --Setup (width,height) screen.title(Sky of Romance)  
screen.bgcolor("black")  
# Set or return the drawing delay in milliseconds, the larger the delay, the slower the drawing
screen.delay(0)
Copy the code

5. Step 3:

Step 3: define 3 different colors of planets with different sizes, velocities, positions and shapes
#shape(): Sets the shape of the turtle. Values: "arrow", "Turtle", "Circle", "square", "triangle", "classic"
#-- Planet -- white star --
t = Turtle(visible = False,shape='circle')  
t.pencolor("white")  
The color of the turtle is the color of the flying planet
t.fillcolor("blue")  
t.penup()  
# Rotation Angle
t.setheading(-10)  
# Coordinates are random
t.goto(width/2,randint(-height/2,height/2))  
  
#-- Planet 2-- little green distant star --
t2 = Turtle(visible = False,shape='turtle')  
The color of the turtle is the color of the flying planet
t2.fillcolor("green")  
t2.penup()  
t2.setheading(-50)  
# Coordinates are random
t2.goto(width,randint(-height,height))  
  
#-- Planet 3-- near red star --
t3 = Turtle(visible = False,shape='circle')  
The color of the turtle is the color of the flying planet
t3.fillcolor("red")  
t3.penup()  
t3.setheading(-90)  
# Coordinates are random
t3.goto(width*2,randint(-height*2,height*2))
Copy the code

5. 6. Smart refrigerator

#-- Step 4 -- define the list of planets for storage
stars = []  
stars2 = []  
stars3 = []
Copy the code

7. Step 5:

Step 5: define the size, speed and position of the three planets and store them in their respective lists
#-- note that 200 is to draw 200 respective planets quit, note too much to be 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))  
    # Generate coordinates randomly
    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 planetS3 = 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)Copy the code

8. Step 6:

#-- Step 6 -- game loop -- start your 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()
Copy the code

9. Rendering

Bjbsair.com/2020-03-25/…

2. Code implementation conditions

python3

Step 1:

#-- Step 1 -- Import module --
from turtle import *  
from random import random,randint
Copy the code

4. Step 2:

Step 2: Initialize the definition
Define screen, window size, title, background color
screen = Screen()  
#-- A little bigger effect is better --Setup (width,height) screen.title(Sky of Romance)  
screen.bgcolor("black")  
# Set or return the drawing delay in milliseconds, the larger the delay, the slower the drawing
screen.delay(0)
Copy the code

5. Step 3:

Step 3: define 3 different colors of planets with different sizes, velocities, positions and shapes
#shape(): Sets the shape of the turtle. Values: "arrow", "Turtle", "Circle", "square", "triangle", "classic"
#-- Planet -- white star --
t = Turtle(visible = False,shape='circle')  
t.pencolor("white")  
The color of the turtle is the color of the flying planet
t.fillcolor("blue")  
t.penup()  
# Rotation Angle
t.setheading(-10)  
# Coordinates are random
t.goto(width/2,randint(-height/2,height/2))  
  
#-- Planet 2-- little green distant star --
t2 = Turtle(visible = False,shape='turtle')  
The color of the turtle is the color of the flying planet
t2.fillcolor("green")  
t2.penup()  
t2.setheading(-50)  
# Coordinates are random
t2.goto(width,randint(-height,height))  
  
#-- Planet 3-- near red star --
t3 = Turtle(visible = False,shape='circle')  
The color of the turtle is the color of the flying planet
t3.fillcolor("red")  
t3.penup()  
t3.setheading(-90)  
# Coordinates are random
t3.goto(width*2,randint(-height*2,height*2))
Copy the code

5. 6. Smart refrigerator

#-- Step 4 -- define the list of planets for storage
stars = []  
stars2 = []  
stars3 = []
Copy the code

7. Step 5:

Step 5: define the size, speed and position of the three planets and store them in their respective lists
#-- note that 200 is to draw 200 respective planets quit, note too much to be 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))  
    # Generate coordinates randomly
    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 planetS3 = 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)Copy the code

8. Step 6:

#-- Step 6 -- game loop -- start your 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()
Copy the code

9. Rendering