From 3567c11ca6b56136c2103042026b2c856ae23c52 Mon Sep 17 00:00:00 2001 From: ennucore Date: Mon, 20 Sep 2021 10:53:21 +0300 Subject: [PATCH] sign --- README.md | 2 ++ turtle_2/turtle_gas.py | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9a29b03..786f71a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Лабораторные работы для "Практики программирования на питоне" +**Чижов Лев** + [1. Построение графиков](http://cs.mipt.ru/python/lessons/lab1.html) - в папке `ipynb` [2. Исполнитель "Черепаха" (ч.1)](http://cs.mipt.ru/python/lessons/lab2.html) - в папке `turtle` diff --git a/turtle_2/turtle_gas.py b/turtle_2/turtle_gas.py index 3032689..aa0a14e 100644 --- a/turtle_2/turtle_gas.py +++ b/turtle_2/turtle_gas.py @@ -5,6 +5,7 @@ import math number_of_turtles = 20 steps_of_time_number = 300 +turtle.screensize(100, 150) pool = [turtle.Turtle(shape='turtle') for i in range(number_of_turtles)] @@ -13,23 +14,31 @@ for unit in pool: unit.speed(350) unit.goto(randint(-200, 200), randint(-150, 150)) unit.left(randint(-180, 180)) + unit.rev_x = False + unit.rev_y = False 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]: + x, y = unit.xcor(), unit.ycor() + if abs(x) >= turtle.screensize()[0] and not unit.rev_x: 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.rev_y = True + elif abs(y) < turtle.screensize()[1]: + unit.rev_y = False 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.seth(angle) + another_unit.seth(-angle) unit.forward(2) another_unit.forward(2)