Browse Source

jumping + turtle gas

master
Lev 3 years ago
parent
commit
3a18697242
  1. 21
      turtle_2/jumping.py
  2. 35
      turtle_2/turtle_gas.py

21
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

35
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)
Loading…
Cancel
Save