IRESTE/CarController.py

26 lines
742 B
Python

import sumolib
from Car import Car
from matplotlib import cm
class CarController:
def __init__(self,path,parentMap,surface):
self.map=parentMap
self.surf=surface
self.cars=[]
self.fromPath(path)
def fromPath(self,path):
for vehicle in sumolib.xml.parse(path,"vehicle"):
self.cars.append(Car(vehicle.id,vehicle.route[0].edges.split(),self.map,self.surf))
def update(self):
for car in self.cars:
car.update(1.0/60)
def draw(self,screen):
cmap = cm.get_cmap('Spectral')
for ind,car in enumerate(self.cars):
color=cmap(ind/len(self.cars))
car.draw([a*255 for a in color[0:3]])
screen.blit(self.surf,(0,0))