diff --git a/Map.py b/Map.py index 9285473..186f30c 100644 --- a/Map.py +++ b/Map.py @@ -14,13 +14,27 @@ class Map: self.net = sumolib.net.readNet(path,withInternal=True) def draw(self,screen): + self.minVal=0 for edge in self.net.getEdges(): color=(255,255,255) if(edge.getFunction()=="internal"): color=(255,0,0) for lane in edge.getLanes(): - lastPos = None - pg.draw.lines(self.surf,color,False,lane.getShape()) + pts=lane.getShape() + pts=map(self.convertPos,pts) + pg.draw.lines(self.surf,color,False,list(pts)) screen.blit(self.surf,(0,0)) - + + def convertPos(self,pos): + bounds=self.net.getBoundary() + bounds[0]-=20 + bounds[1]-=10 + bounds[2]+=10 + bounds[3]+=10 + scale=min(self.surf.get_width()/(bounds[2]-bounds[0]),self.surf.get_height()/(bounds[3]-bounds[1])) + + x=pos[0]*scale-bounds[0] + y=pos[1]*scale-bounds[1] + + return (x,y) diff --git a/main.py b/main.py index a89b7d6..ff798f2 100644 --- a/main.py +++ b/main.py @@ -28,6 +28,8 @@ while running: running = False elif event.type == pg.KEYDOWN and event.key == pg.K_ESCAPE: running = False + elif event.type == pg.KEYDOWN and event.key == pg.K_q: + running = False m.draw(screen) pg.display.flip()