-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfo.py
105 lines (83 loc) · 2.26 KB
/
info.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import sys
import time
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
f = open("info.txt", "r")
MAXY = 100
current = 0
fig, ax = plt.subplots()
xdata, ydata = [], []
xdata2, ydata2 = [], []
xdata3, ydata3 = [], []
ln1, ln2, ln3, ln4 = ax.plot([], [], 'r-',
[], [], 'b-',
[], [], 'y-',
[], [], 'c-',
animated=False) #animated is associated with blit
plt.setp(ln1, label='Ant')
plt.setp(ln2, label='Doodlebug')
plt.setp(ln3, label='Plant')
plt.legend(loc=0, numpoints=1)
def init():
ax.set_xlim(0, 500)
ax.set_ylim(0, MAXY)
return ln1,ln2,ln3,ln4
def update(i): #i is an int from 0 to frames-1, and keep looping
global MAXY
global f
filenum = f.tell()
#print(filenum)
global current
xlen = len(open("info.txt",'r').readlines())
wait=0
while current >= xlen:
wait = wait+1
if wait > 10:
sys.exit(0)
time.sleep(1)
xlen = len(open("info.txt",'r').readlines())
line = f.readline()
line = line.replace('\n','')
str1 = line.split(' ')
while len(str1) < 4 :
f.close()
f = open("info.txt", "r")
f.seek(filenum)
line = f.readline()
line = line.replace('\n','')
str1 = line.split(' ')
time.sleep(1)
x = int(str1[0])
y1 = int(str1[1])
y2 = int(str1[2])
y3 = int(str1[3])
current = x
ax.set_xlim(x-490, 10+x)
ax.set_ylim(0, MAXY)
#print(x, " ", y1)
xdata.append(x)
ydata.append(y1)
xdata2.append(x)
ydata2.append(y2)
xdata3.append(x)
ydata3.append(y3)
if x % 500 == 0:
MAXY = y1
if y1 > MAXY:
MAXY = y1
if y2 > MAXY:
MAXY = y2
if y3 > MAXY:
MAXY = y3
ln1.set_data(xdata, ydata)
ln2.set_data(xdata2, ydata2)
ln3.set_data(xdata3, ydata3)
return ln1, ln2, ln3, ln4
def main():
ani = FuncAnimation(fig, update, frames=500, interval = 1,
init_func=init, blit=False)
# ani.save('animation.mp4', writer='ffmpeg', fps=30) /save as .mp4
plt.show()
if __name__ == '__main__':
main()