From 3a18697242f6cce5b140e1f59239947a4648ef51 Mon Sep 17 00:00:00 2001 From: ennucore Date: Mon, 20 Sep 2021 10:30:23 +0300 Subject: [PATCH] jumping + turtle gas --- turtle_2/jumping.py | 21 +++++++++++++++++++++ turtle_2/turtle_gas.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 turtle_2/jumping.py create mode 100644 turtle_2/turtle_gas.py diff --git a/turtle_2/jumping.py b/turtle_2/jumping.py new file mode 100644 index 0000000..fbdab39 --- /dev/null +++ b/turtle_2/jumping.py @@ -0,0 +1,21 @@ +import turtle + + +turtle.shape('turtle') +Vx, Vy = 5, 50 +t = 0 +dt = 0.2 +ay = -3 +x, y = 0, 0 +turtle.up() +dx0, dy0 = 250, 100 +turtle.goto(-dx0, -dy0) +turtle.down() +while True: + t += dt + x += Vx * dt + y += Vy * dt + ay * dt**2/2 + Vy += ay * dt + turtle.goto(x - dx0, y - dy0) + if y <= 0: + Vy = -Vy * 0.8 diff --git a/turtle_2/turtle_gas.py b/turtle_2/turtle_gas.py new file mode 100644 index 0000000..3032689 --- /dev/null +++ b/turtle_2/turtle_gas.py @@ -0,0 +1,35 @@ +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) +