Skip to content
Snippets Groups Projects
Commit 72c26453 authored by Egli Adrian (IT-SCI-API-PFI)'s avatar Egli Adrian (IT-SCI-API-PFI)
Browse files

demo.py: screen recordering

parent e9a65ca2
No related branches found
No related tags found
No related merge requests found
...@@ -126,6 +126,10 @@ class Demo: ...@@ -126,6 +126,10 @@ class Demo:
self.create_renderer() self.create_renderer()
self.action_size = 4 self.action_size = 4
self.max_frame_rate = 60 self.max_frame_rate = 60
self.record_frames = None
def set_record_frames(self,record_frames):
self.record_frames = record_frames
def create_renderer(self): def create_renderer(self):
self.renderer = RenderTool(self.env, gl="PILSVG") self.renderer = RenderTool(self.env, gl="PILSVG")
...@@ -151,7 +155,7 @@ class Demo: ...@@ -151,7 +155,7 @@ class Demo:
for iAgent in range(self.env.get_num_agents()): for iAgent in range(self.env.get_num_agents()):
action = 2 action = 2
if True: if False:
if not ((step) % 2 == 0): if not ((step) % 2 == 0):
if iAgent == 3: if iAgent == 3:
action = 0 action = 0
...@@ -179,6 +183,10 @@ class Demo: ...@@ -179,6 +183,10 @@ class Demo:
break break
im = self.renderer.getImage()
self.renderer.gl.saveImage(self.record_frames.format(step))
# ensure that the rendering is not faster then the maximal allowed frame rate # ensure that the rendering is not faster then the maximal allowed frame rate
end_frame_time_stamp = datetime.now() end_frame_time_stamp = datetime.now()
frame_exe_time = end_frame_time_stamp - begin_frame_time_stamp frame_exe_time = end_frame_time_stamp - begin_frame_time_stamp
...@@ -212,18 +220,21 @@ if False: ...@@ -212,18 +220,21 @@ if False:
demo_002.run_demo() demo_002.run_demo()
demo_002 = None demo_002 = None
demo_flatland_000 = Demo(Scenario_Generator.load_scenario('./env-data/railway/example_flatland_000.pkl')) demo_flatland_000 = Demo(Scenario_Generator.load_scenario('./env-data/railway/example_flatland_000.pkl'))
demo_flatland_000.renderer.resize() demo_flatland_000.renderer.resize()
demo_flatland_000.run_demo(60) demo_flatland_000.run_demo(60)
demo_flatland_000 = None demo_flatland_000 = None
demo_flatland_000 = Demo(Scenario_Generator.load_scenario('./env-data/railway/example_network_003.pkl'))
demo_flatland_000.renderer.resize()
demo_flatland_000.set_max_framerate(5)
demo_flatland_000.run_demo(30)
demo_flatland_000 = None
demo_flatland_000 = Demo(Scenario_Generator.load_scenario('./env-data/railway/example_flatland_001.pkl')) demo_flatland_000 = Demo(Scenario_Generator.load_scenario('./env-data/railway/example_flatland_001.pkl'))
demo_flatland_000.renderer.resize() demo_flatland_000.renderer.resize()
demo_flatland_000.set_record_frames('./rendering/frame_{:04d}.bmp')
demo_flatland_000.run_demo(60) demo_flatland_000.run_demo(60)
demo_flatland_000 = None demo_flatland_000 = None
demo_flatland_000 = Demo(Scenario_Generator.load_scenario('./env-data/railway/example_network_003.pkl'))
demo_flatland_000.renderer.resize()
demo_flatland_000.set_max_framerate(5)
demo_flatland_000.run_demo(30)
demo_flatland_000 = None
...@@ -43,6 +43,9 @@ class GraphicsLayer(object): ...@@ -43,6 +43,9 @@ class GraphicsLayer(object):
def getImage(self): def getImage(self):
pass pass
def saveImage(self,filename):
pass
def adaptColor(self, color, lighten=False): def adaptColor(self, color, lighten=False):
if type(color) is str: if type(color) is str:
if color == "red" or color == "r": if color == "red" or color == "r":
......
...@@ -160,6 +160,13 @@ class PILGL(GraphicsLayer): ...@@ -160,6 +160,13 @@ class PILGL(GraphicsLayer):
img = self.alpha_composite_layers() img = self.alpha_composite_layers()
return array(img) return array(img)
def saveImage(self,filename):
print(filename)
img = self.alpha_composite_layers()
img.save(filename)
def create_image(self, opacity=255): def create_image(self, opacity=255):
img = Image.new("RGBA", (self.widthPx, self.heightPx), (255, 255, 255, opacity)) img = Image.new("RGBA", (self.widthPx, self.heightPx), (255, 255, 255, opacity))
return img return img
......
...@@ -703,6 +703,7 @@ class RenderTool(object): ...@@ -703,6 +703,7 @@ class RenderTool(object):
def getImage(self): def getImage(self):
return self.gl.getImage() return self.gl.getImage()
def plotTreeObs(self, gObs): def plotTreeObs(self, gObs):
nBranchFactor = 4 nBranchFactor = 4
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment