From 57bd97644a0acac609fd6094c52774df08a1a842 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 7 Feb 2022 09:04:17 +0100 Subject: [PATCH] =?UTF-8?q?ajout=C3=A9=20la=20mise=20=C3=A0=20l'echelle=20?= =?UTF-8?q?pour=20tenir=20dans=20l'ecran?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Map.py | 20 +++++++++++++++++--- main.py | 2 ++ 2 files changed, 19 insertions(+), 3 deletions(-) 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()