From d35beaea813031b852a52d1394422b62ba62b996 Mon Sep 17 00:00:00 2001 From: timofej Date: Thu, 17 Aug 2023 13:38:18 +0200 Subject: [PATCH] Fix process info --- neuropercolation/display.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/neuropercolation/display.py b/neuropercolation/display.py index 5e1e775..f5f9c01 100644 --- a/neuropercolation/display.py +++ b/neuropercolation/display.py @@ -67,7 +67,7 @@ class Simulate2Layers: def __init__(self, dim, eps, - res=10, + res=4, draw='pygame', state_to_color_cb=None, *args, **kwargs): @@ -110,7 +110,8 @@ class Simulate2Layers: time_ds_end = time.time() self.print_process_info(evolve_duration=(time_ca_end - time_ca_start), draw_duration=(time_ds_end - time_ca_end), - evolution_step=self._cellular_automaton.evolution_step) + evolution_step=self._cellular_automaton.evolution_step, + runlendig=len(str(last_evolution_step))) self._sleep_to_keep_rate(time.time() - time_ca_start, evolutions_per_second) try: self.__draw_engine._pygame.quit() @@ -160,11 +161,9 @@ class Simulate2Layers: def __draw_cell_surface(self, surface_pos, cell_color): return self.__draw_engine.fill_surface_with_color((surface_pos, self.__cell_size), cell_color) - def print_process_info(self, evolve_duration, draw_duration, evolution_step): + def print_process_info(self, evolve_duration, draw_duration, evolution_step, runlendig): self.__draw_engine.fill_surface_with_color(((0, 0), (self.__rect.width, 30))) - self.__draw_engine.write_text((10, 5), "CA: " + "{0:.4f}".format(evolve_duration) + "s") - self.__draw_engine.write_text((310, 5), "Display: " + "{0:.4f}".format(draw_duration) + "s") - self.__draw_engine.write_text((660, 5), "Step: " + str(evolution_step)) + self.__draw_engine.write_text((0, 5), f'Step: {evolution_step:>{runlendig}} FPS: {int(1/(evolve_duration+draw_duration))}') def _is_not_user_terminated(self): return self.__draw_engine.is_active() @@ -173,7 +172,8 @@ class Simulate4Layers: def __init__(self, dim, eps, - res=10, + coupling=[], + res=4, draw='pygame', state_to_color_cb=None, *args, **kwargs): @@ -187,7 +187,7 @@ class Simulate4Layers: :param state_to_color_cb: A callback to define the draw color of CA states (default: red for states != 0) """ super().__init__(*args, **kwargs) - self._cellular_automaton = NeuropercolationCoupled(dim,eps) + self._cellular_automaton = NeuropercolationCoupled(dim,eps,coupling) self.__cell_size = [res,res] self.__gridside = dim*res self.__samegap = 10 @@ -216,7 +216,8 @@ class Simulate4Layers: time_ds_end = time.time() self.print_process_info(evolve_duration=(time_ca_end - time_ca_start), draw_duration=(time_ds_end - time_ca_end), - evolution_step=self._cellular_automaton.evolution_step) + evolution_step=self._cellular_automaton.evolution_step, + runlendig=len(str(last_evolution_step))) self._sleep_to_keep_rate(time.time() - time_ca_start, evolutions_per_second) try: self.__draw_engine._pygame.quit() @@ -267,11 +268,9 @@ class Simulate4Layers: def __draw_cell_surface(self, surface_pos, cell_color): return self.__draw_engine.fill_surface_with_color((surface_pos, self.__cell_size), cell_color) - def print_process_info(self, evolve_duration, draw_duration, evolution_step): + def print_process_info(self, evolve_duration, draw_duration, evolution_step, runlendig): self.__draw_engine.fill_surface_with_color(((0, 0), (self.__rect.width, 30))) - self.__draw_engine.write_text((10, 5), "CA: " + "{0:.4f}".format(evolve_duration) + "s") - self.__draw_engine.write_text((310, 5), "Display: " + "{0:.4f}".format(draw_duration) + "s") - self.__draw_engine.write_text((660, 5), "Step: " + str(evolution_step)) + self.__draw_engine.write_text((0, 5), f'Step: {evolution_step:>{runlendig}} FPS: {int(1/(evolve_duration+draw_duration))}') def _is_not_user_terminated(self): return self.__draw_engine.is_active()