From 2a7ce437b081242fda89d9d98563316307925b58 Mon Sep 17 00:00:00 2001
From: "Egli Adrian (IT-SCI-API-PFI)" <adrian.egli@sbb.ch>
Date: Mon, 30 Sep 2019 23:32:35 +0200
Subject: [PATCH] rendering city

---
 flatland/utils/graphics_layer.py | 2 +-
 flatland/utils/graphics_pil.py   | 8 ++++++--
 flatland/utils/rendertools.py    | 3 ++-
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/flatland/utils/graphics_layer.py b/flatland/utils/graphics_layer.py
index b2dac463..11a9addc 100644
--- a/flatland/utils/graphics_layer.py
+++ b/flatland/utils/graphics_layer.py
@@ -65,7 +65,7 @@ class GraphicsLayer(object):
     def get_cmap(self, *args, **kwargs):
         return plt.get_cmap(*args, **kwargs)
 
-    def set_rail_at(self, row, col, binTrans, iTarget=None, isSelected=False, rail_grid=None):
+    def set_rail_at(self, row, col, binTrans, iTarget=None, isSelected=False, rail_grid=None, num_agents=None):
         """ Set the rail at cell (row, col) to have transitions binTrans.
             The target argument can contain the index of the agent to indicate
             that agent's target is at that cell, so that a station can be
diff --git a/flatland/utils/graphics_pil.py b/flatland/utils/graphics_pil.py
index e325758e..0597f4e2 100644
--- a/flatland/utils/graphics_pil.py
+++ b/flatland/utils/graphics_pil.py
@@ -499,7 +499,7 @@ class PILSVG(PILGL):
                                           False)[0]
         self.draw_image_row_col(colored_rail, (row, col), layer=PILGL.PREDICTION_PATH_LAYER)
 
-    def set_rail_at(self, row, col, binary_trans, target=None, is_selected=False, rail_grid=None,
+    def set_rail_at(self, row, col, binary_trans, target=None, is_selected=False, rail_grid=None, num_agents=None,
                     show_debug=True):
 
         if binary_trans in self.pil_rail:
@@ -511,8 +511,12 @@ class PILSVG(PILGL):
                 if show_debug:
                     self.text_rowcol((row + 0.8, col + 0.0), strText=str(target), layer=PILGL.TARGET_LAYER)
 
+            city_size = 1
+            if num_agents is not None:
+                city_size = max(1,np.log(1+num_agents))
+
             if binary_trans == 0:
-                if self.background_grid[col][row] <= 4 + ((col * row + col) % 10):
+                if self.background_grid[col][row] <= 4 + np.ceil(((col * row + col) % 10)/city_size):
                     a = int(self.background_grid[col][row])
                     a = a % len(self.dBuildings)
                     if (col + row + col * row) % 13 > 11:
diff --git a/flatland/utils/rendertools.py b/flatland/utils/rendertools.py
index 99958bf3..42203368 100644
--- a/flatland/utils/rendertools.py
+++ b/flatland/utils/rendertools.py
@@ -529,7 +529,8 @@ class RenderTool(object):
                         is_selected = False
 
                     self.gl.set_rail_at(r, c, transitions, target=target, is_selected=is_selected,
-                                        rail_grid=env.rail.grid, show_debug=self.show_debug)
+                                        rail_grid=env.rail.grid, num_agents=env.get_num_agents(),
+                                        show_debug=self.show_debug)
 
             self.gl.build_background_map(targets)
 
-- 
GitLab