-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
65 lines (59 loc) · 1.66 KB
/
test.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
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib.animation import FFMpegWriter
roadWidth = 2000
max_frame = 3600
fig = plt.figure(figsize=(6, 6))
plt.ion()
ax = plt.gca()
ax.grid()
ln1, = ax.plot([], [], 'ro')
ln2, = ax.plot([], [], 'ro', color='r')
Frames = []
# denote that each line is Frame \t id \t x \t y \t
file1 = open('xyzoutputAn.xyz', 'r')
Lines = file1.readlines()
cars = []
lastID = 0
for line in Lines:
r = line.split('\t')
frameID = int(r[1])
x = float(r[2])
y = float(r[3])
cars.append((x, y))
if lastID != frameID:
Frames.append(cars)
cars = []
lastID = frameID
max_frame = frameID
file1.close()
def init():
global max_frame
ax.set_xlim(-2, roadWidth)
ax.set_ylim(-10, 20)
plt.axline((0, -2), (roadWidth, -2))
plt.axline((0, 2), (roadWidth, 2))
plt.axline((0, 6), (roadWidth, 6))
plt.axline((0, 10), (roadWidth, 10))
plt.axline((0, 14), (roadWidth, 14))
return ln1,
def update(i):
print("generating frame:" + str(i))
x_in = []
y_in = []
cars = Frames[i]
for j in range(len(cars)-1):
car = Frames[i][j]
x_in.append(car[0])
y_in.append(car[1])
ln2.set_data(x_in, y_in)
return ln2,
# 500 is how many frames you want to genearte
ani = animation.FuncAnimation(
fig, update, range(max_frame), init_func=init, interval=30)
ani.save('roll1000.gif', writer='Pillow', fps=30)
#f = r"road.mp4"
#writer = FFMpegWriter(fps=15, metadata=dict(artist='Me'), bitrate=1800)
#ani.save("movie.mp4", writer=writer)
plt.show()