Лабораторные работы по Python, ЛФИ, 1 семестр
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.1 KiB

from random import randint
import turtle
import math
number_of_turtles = 20
steps_of_time_number = 300
pool = [turtle.Turtle(shape='turtle') for i in range(number_of_turtles)]
for unit in pool:
unit.penup()
unit.speed(350)
unit.goto(randint(-200, 200), randint(-150, 150))
unit.left(randint(-180, 180))
for i in range(steps_of_time_number):
for unit in pool:
x, y = unit.xcor() + turtle.screensize()[0] / 2, unit.ycor() + turtle.screensize()[1] / 2
if x <= 0 or x >= turtle.screensize()[0]:
unit.seth(90 - unit.heading())
if y <= 0 or y >= turtle.screensize()[1]:
unit.seth(-unit.heading())
unit.forward(7)
for another_unit in pool:
if another_unit == unit:
continue
if math.hypot(another_unit.xcor() - unit.xcor(), another_unit.ycor() - unit.ycor()) < 6:
angle = randint(-180, 180)
unit.left(angle)
another_unit.right(angle)
unit.forward(2)
another_unit.forward(2)