-
Notifications
You must be signed in to change notification settings - Fork 0
/
simulator_v0_0_2.py
57 lines (57 loc) · 1.61 KB
/
simulator_v0_0_2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from turtle import *
from math import *
pos = [Vec2D(100, -100), Vec2D(100, 100), Vec2D(-100, 100), Vec2D(-100, -100)]
vel = [Vec2D(15, -12), Vec2D(-12, 27), Vec2D(-23, 24), Vec2D(-13, 18)]
sta = [[0, 150, 210, 150],
[150, 0, 150, 0],
[210, 150, 0, 150],
[150, 0, 150, 0]]
ela = [[0, 0.000001, 0.000001, 0.000001],
[0.000001, 0, 0.000001, 0],
[0.000001, 0.000001, 0, 0.000001],
[0.000001, 0, 0.000001, 0]]
pla = [[0, 0, 0, 0],
[0, 0, 0, 0.001],
[0, 0, 0, 0],
[0, 0.001, 0, 0]]
col = ['red', 'blue', 'yellow', 'green']
tur = []
pre = 0.01
cof = 0.1
num = 4
cnt = 0
bgcolor('black')
title('GPE Simulator')
for i in range(num):
tur.append(Turtle())
tur[i].pencolor(col[i])
tur[i].speed(0)
tur[i].penup()
tur[i].goto(pos[i])
tur[i].shape('circle')
tur[i].dot(5)
tur[i].pendown()
while True:
cnt += 1
for i in range(num):
if abs(vel[i]) * pre * cof > 1:
vel[i] = Vec2D(0, 0)
else:
vel[i] -= abs(vel[i]) * vel[i] * pre * cof
for i in range(num):
for j in range(num):
if sta[i][j] == 0 or ela[i][j] == 0:
continue
vel[i] -= (abs(pos[j] - pos[i]) - sta[i][j]) ** 3 / abs(pos[j] - pos[i]) * pos[i] * pre * ela[i][j]
tmp = vel.copy()
for i in range(num):
for j in range(num):
tmp[j] += vel[i] * pla[i][j]
tmp[i] *= 1 - pla[i][j]
vel = tmp.copy()
if cnt == 10000:
vel[3] += Vec2D(-100, -100)
for i in range(num):
pos[i] += vel[i] * pre
if cnt % 100 == 0:
tur[i].goto(pos[i])