Вот так
import turtle
from random import randint
HEIGHT = 300
WEIGHT = 400
turtle.bgcolor('Black')
snowFlakes = []
turtle.tracer(2)
turtle.speed(1)
# Создаем черепашек
for i in range(20):
flake = turtle.Turtle()
flake.penup()
flake.color('white')
flake.shape('circle')
flake.goto(randint(-WEIGHT, WEIGHT), HEIGHT)
flake.shapesize(randint(4, 15) / 10)
snowFlakes.append(flake)
# Сортируем черепашек по их вертикальной позиции (Y)
snowFlakes.sort(key=lambda flake: flake.ycor())
while True:
for flake in snowFlakes:
if flake.ycor() > -HEIGHT:
flake.goto(flake.xcor() + 0.5, flake.ycor() - 3)
elif flake.ycor() <= -HEIGHT:
flake.goto(randint(-WEIGHT, WEIGHT), HEIGHT)
flake.shapesize(randint(5, 20) / 10)
turtle.exitonclick()
вот код:
import turtle
from random import randint
HEIGHT = 300
WEIGHT = 400
turtle_speed = 1
temp = 0
turtle.bgcolor('Black')
snowFlakes = []
turtle.tracer(2)
turtle.speed(1)
for i in range(20):
flake = turtle.Turtle()
flake.penup()
flake.color('white')
flake.shape('circle')
flake.goto(randint(-WEIGHT, WEIGHT), HEIGHT)
flake.shapesize(randint(4, 15) / 10)
snowFlakes.append(flake)
#пытался сортировать тут
while True:
for flake in snowFlakes:
if flake.ycor() > -HEIGHT:
flake.goto(flake.xcor() + 0.5, flake.ycor() - 3)
elif flake.ycor() <= -HEIGHT:
flake.goto(randint(-WEIGHT, WEIGHT), HEIGHT)
flake.shapesize(randint(5, 20) / 10)
break
turtle.exitonclick()