diff --git a/flatland/utils/graphics_pil.py b/flatland/utils/graphics_pil.py index 8d10312b68df5709fa41fa63ad2977dca0b67900..ed48654cba62ddefaac736773ebdfe5830ccd11e 100644 --- a/flatland/utils/graphics_pil.py +++ b/flatland/utils/graphics_pil.py @@ -79,19 +79,38 @@ class PILGL(GraphicsLayer): self.window_root = None self.window_open = False self.firstFrame = True + self.old_background_image = (None, None, None) self.create_layers() def build_background_map(self, dTargets): - self.background_grid = np.zeros(shape=(self.width, self.height)) - for x in range(self.width): - for y in range(self.height): - distance = int(np.ceil(np.sqrt(self.width ** 2.0 + self.height ** 2.0))) - for rc in dTargets: - r = rc[1] - c = rc[0] - d = int(np.floor(np.sqrt((x - r) ** 2 + (y - c) ** 2))) - distance = min(d, distance) - self.background_grid[x][y] = distance + x = self.old_background_image + rebuild = False + if x[0] is None: + rebuild = True + else: + if len(x[0]) != len(dTargets): + rebuild = True + else: + if x[0] != dTargets: + rebuild = True + if x[1] != self.width: + rebuild = True + if x[2] != self.height: + rebuild = True + + if rebuild: + self.background_grid = np.zeros(shape=(self.width, self.height)) + for x in range(self.width): + for y in range(self.height): + distance = int(np.ceil(np.sqrt(self.width ** 2.0 + self.height ** 2.0))) + for rc in dTargets: + r = rc[1] + c = rc[0] + d = int(np.floor(np.sqrt((x - r) ** 2 + (y - c) ** 2))) + distance = min(d, distance) + self.background_grid[x][y] = distance + + self.old_background_image = (dTargets, self.width, self.height) def rgb_s2i(self, sRGB): """ convert a hex RGB string like 0091ea to 3-tuple of ints """ diff --git a/notebooks/Scene_Editor.ipynb b/notebooks/Scene_Editor.ipynb index 75abead1a386876eddc26a025a7f3fb1f8893a4f..df314171c1988137305d281e5d7873fc27f4b314 100644 --- a/notebooks/Scene_Editor.ipynb +++ b/notebooks/Scene_Editor.ipynb @@ -70,7 +70,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "b9ba3ece379e463184ad5217c1f4c289", + "model_id": "9d466178f2f04a33b5589de583a565b7", "version_major": 2, "version_minor": 0 },