ajouté la mise à l'echelle pour tenir dans l'ecran
This commit is contained in:
parent
7f4c8b6e8b
commit
57bd97644a
20
Map.py
20
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user