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