ajouté la mise à l'echelle pour tenir dans l'ecran

This commit is contained in:
leo 2022-02-07 09:04:17 +01:00
parent 7f4c8b6e8b
commit 57bd97644a
Signed by: leo
GPG Key ID: 0DD993BFB2B307DB
2 changed files with 19 additions and 3 deletions

20
Map.py
View File

@ -14,13 +14,27 @@ class Map:
self.net = sumolib.net.readNet(path,withInternal=True) self.net = sumolib.net.readNet(path,withInternal=True)
def draw(self,screen): def draw(self,screen):
self.minVal=0
for edge in self.net.getEdges(): for edge in self.net.getEdges():
color=(255,255,255) color=(255,255,255)
if(edge.getFunction()=="internal"): if(edge.getFunction()=="internal"):
color=(255,0,0) color=(255,0,0)
for lane in edge.getLanes(): for lane in edge.getLanes():
lastPos = None pts=lane.getShape()
pg.draw.lines(self.surf,color,False,lane.getShape()) pts=map(self.convertPos,pts)
pg.draw.lines(self.surf,color,False,list(pts))
screen.blit(self.surf,(0,0)) 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)

View File

@ -28,6 +28,8 @@ while running:
running = False running = False
elif event.type == pg.KEYDOWN and event.key == pg.K_ESCAPE: elif event.type == pg.KEYDOWN and event.key == pg.K_ESCAPE:
running = False running = False
elif event.type == pg.KEYDOWN and event.key == pg.K_q:
running = False
m.draw(screen) m.draw(screen)
pg.display.flip() pg.display.flip()