-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvisualiser.py
72 lines (60 loc) · 2.06 KB
/
visualiser.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
#! /usr/bin/python2
from numpy import *
import numpy as np
import time
import sys
pygame = (int)(sys.argv[1])
mayavi = abs(pygame-1)
def get_trajectory(filename):
data =[]
with open(filename) as input_file:
try:
for line in input_file:
line = line.strip()
for number in line.split():
data.append(float(number))
except IOError:
print "Could not read file:", filename
data = np.reshape(data,(1000,3))
return data
num = 0
filename = "trajectory" +str(num) + ".bin"
data = get_trajectory(filename)
if pygame:
# Pygame initialzation
import pygame
pygame.init()
xResolution = 640
yResolution = 480
surface = pygame.display.set_mode((xResolution, yResolution))
xCenter = int(xResolution / 2)
yCenter = int(yResolution / 2)
font = pygame.font.Font(None, 20)
# Loop timesteps forever
timestep = 0
while True:
filename = "trajectory" +str(timestep) + ".bin"
# Increment timestep
timestep = timestep + 100
# Pygame update screen
pygame.display.update()
surface.fill((0,0,0))
data = get_trajectory(filename)
for i in range(0, len(data)):
# Pygame draw body
pygame.draw.circle(surface, (random.triangular(0,125,255),random.triangular(0,125,255),random.triangular(0,125,255)), (int(data[i][0]*640/200), int(data[i][1]*480/100)), 3 ,0)
# Pygame write elapsed time
text = font.render("Time: " + str(int(timestep * 0.1))+"s", True, (255,255,255))
surface.blit(text,(10,10))
time.sleep(0.1)
if mayavi:
from mayavi import mlab
from mayavi.mlab import *
mlab.figure(1, bgcolor=(1, 1, 1))
timestep = 0
while True:
filename = "trajectory" +str(timestep) + ".bin"
# Increment timestep
timestep = timestep + 100
data = get_trajectory(filename)
points3d(zip(*data)[0], zip(*data)[1], zip(*data)[2], color = (1,0,0), colormap = "bone", scale_factor = 0.9)