diff --git a/flatland/utils/graphics_layer.py b/flatland/utils/graphics_layer.py
index b2dac4637d1560f9d1ac5ae485d8bf8bd5c2c97e..11a9addcb882d5de3069e2f1703de8dbf42c92ff 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 e325758e57c12cf0d97b7c519b8c7a621bb5e4be..8774158c340752e3479b07670132f8a29d1b7895 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)/1.5)
+
             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 99958bf38449ef8eb58c519990f1975106409c4e..42203368cd0a2c1670b90bb00019caeae9132c75 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)