From 2db30885300a7d505601f7061b44e9b1a1b197a0 Mon Sep 17 00:00:00 2001 From: timofej Date: Sun, 20 Aug 2023 02:18:19 +0200 Subject: [PATCH] Use pygame built-in is_active() function and del save_states option --- neuropercolation/display.py | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/neuropercolation/display.py b/neuropercolation/display.py index 518cb47..c2e3c31 100644 --- a/neuropercolation/display.py +++ b/neuropercolation/display.py @@ -106,8 +106,7 @@ class Simulate1Layer: def run(self, evolutions_per_second=0, evolutions_per_draw=1, - last_evolution_step=0, - save_states=True): + last_evolution_step=0): """ Evolves and draws the CellularAutomaton :param evolutions_per_second: 0 = as fast as possible | > 0 to slow down the CellularAutomaton @@ -118,7 +117,7 @@ class Simulate1Layer: self._track() with contextlib.suppress(KeyboardInterrupt): - while self.__active and self._not_at_the_end(last_evolution_step): + while self.__draw_engine.is_active() and self._not_at_the_end(last_evolution_step): time_ca_start = time.time() self._cellular_automaton.evolve(evolutions_per_draw) self._track() @@ -132,10 +131,6 @@ class Simulate1Layer: runlendig=len(str(last_evolution_step))) self._sleep_to_keep_rate(time.time() - time_ca_start, evolutions_per_second) - for event in self.__draw_engine._pygame.event.get(): - if event.type == self.__draw_engine._pygame.QUIT: - self.__active = False - if self.__draw_engine is not None: try: self.__draw_engine._pygame.quit() @@ -280,8 +275,7 @@ class Simulate2Layers: def run(self, evolutions_per_second=0, evolutions_per_draw=1, - last_evolution_step=0, - save_states=True): + last_evolution_step=0): """ Evolves and draws the CellularAutomaton :param evolutions_per_second: 0 = as fast as possible | > 0 to slow down the CellularAutomaton @@ -291,7 +285,7 @@ class Simulate2Layers: """ self._track() with contextlib.suppress(KeyboardInterrupt): - while self.__active and self._not_at_the_end(last_evolution_step): + while self.__draw_engine.is_active() and self._not_at_the_end(last_evolution_step): time_ca_start = time.time() self._cellular_automaton.evolve(evolutions_per_draw) self._track() @@ -305,10 +299,6 @@ class Simulate2Layers: runlendig=len(str(last_evolution_step))) self._sleep_to_keep_rate(time.time() - time_ca_start, evolutions_per_second) - for event in self.__draw_engine._pygame.event.get(): - if event.type == self.__draw_engine._pygame.QUIT: - self.__active = False - if self.__draw_engine is not None: try: self.__draw_engine._pygame.quit() @@ -459,8 +449,7 @@ class Simulate4Layers: def run(self, evolutions_per_second=0, evolutions_per_draw=1, - last_evolution_step=0, - save_states=True): + last_evolution_step=0): """ Evolves and draws the CellularAutomaton :param evolutions_per_second: 0 = as fast as possible | > 0 to slow down the CellularAutomaton @@ -470,7 +459,7 @@ class Simulate4Layers: """ with contextlib.suppress(KeyboardInterrupt): self._track() - while self.__active and self._not_at_the_end(last_evolution_step): + while self.__draw_engine.is_active() and self._not_at_the_end(last_evolution_step): time_ca_start = time.time() self._cellular_automaton.evolve(evolutions_per_draw) self._track() @@ -484,9 +473,6 @@ class Simulate4Layers: runlendig=len(str(last_evolution_step))) self._sleep_to_keep_rate(time.time() - time_ca_start, evolutions_per_second) - for event in self.__draw_engine._pygame.event.get(): - if event.type == self.__draw_engine._pygame.QUIT: - self.__active = False if self.__draw_engine is not None: try: self.__draw_engine._pygame.quit()