|
|
@ -5,6 +5,7 @@ import math |
|
|
|
|
|
|
|
|
|
|
|
number_of_turtles = 20 |
|
|
|
number_of_turtles = 20 |
|
|
|
steps_of_time_number = 300 |
|
|
|
steps_of_time_number = 300 |
|
|
|
|
|
|
|
turtle.screensize(100, 150) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pool = [turtle.Turtle(shape='turtle') for i in range(number_of_turtles)] |
|
|
|
pool = [turtle.Turtle(shape='turtle') for i in range(number_of_turtles)] |
|
|
@ -13,23 +14,31 @@ for unit in pool: |
|
|
|
unit.speed(350) |
|
|
|
unit.speed(350) |
|
|
|
unit.goto(randint(-200, 200), randint(-150, 150)) |
|
|
|
unit.goto(randint(-200, 200), randint(-150, 150)) |
|
|
|
unit.left(randint(-180, 180)) |
|
|
|
unit.left(randint(-180, 180)) |
|
|
|
|
|
|
|
unit.rev_x = False |
|
|
|
|
|
|
|
unit.rev_y = False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for i in range(steps_of_time_number): |
|
|
|
for i in range(steps_of_time_number): |
|
|
|
for unit in pool: |
|
|
|
for unit in pool: |
|
|
|
x, y = unit.xcor() + turtle.screensize()[0] / 2, unit.ycor() + turtle.screensize()[1] / 2 |
|
|
|
x, y = unit.xcor(), unit.ycor() |
|
|
|
if x <= 0 or x >= turtle.screensize()[0]: |
|
|
|
if abs(x) >= turtle.screensize()[0] and not unit.rev_x: |
|
|
|
unit.seth(90 - unit.heading()) |
|
|
|
unit.seth(90 - unit.heading()) |
|
|
|
if y <= 0 or y >= turtle.screensize()[1]: |
|
|
|
unit.rev_x = True |
|
|
|
|
|
|
|
elif not abs(x) >= turtle.screensize()[0]: |
|
|
|
|
|
|
|
unit.rev_x = False |
|
|
|
|
|
|
|
if abs(y) >= turtle.screensize()[1] and not unit.rev_y: |
|
|
|
unit.seth(-unit.heading()) |
|
|
|
unit.seth(-unit.heading()) |
|
|
|
|
|
|
|
unit.rev_y = True |
|
|
|
|
|
|
|
elif abs(y) < turtle.screensize()[1]: |
|
|
|
|
|
|
|
unit.rev_y = False |
|
|
|
unit.forward(7) |
|
|
|
unit.forward(7) |
|
|
|
for another_unit in pool: |
|
|
|
for another_unit in pool: |
|
|
|
if another_unit == unit: |
|
|
|
if another_unit == unit: |
|
|
|
continue |
|
|
|
continue |
|
|
|
if math.hypot(another_unit.xcor() - unit.xcor(), another_unit.ycor() - unit.ycor()) < 6: |
|
|
|
if math.hypot(another_unit.xcor() - unit.xcor(), another_unit.ycor() - unit.ycor()) < 6: |
|
|
|
angle = randint(-180, 180) |
|
|
|
angle = randint(-180, 180) |
|
|
|
unit.left(angle) |
|
|
|
unit.seth(angle) |
|
|
|
another_unit.right(angle) |
|
|
|
another_unit.seth(-angle) |
|
|
|
unit.forward(2) |
|
|
|
unit.forward(2) |
|
|
|
another_unit.forward(2) |
|
|
|
another_unit.forward(2) |
|
|
|
|
|
|
|
|
|
|
|