Use pygame built-in is_active() function and del save_states option
This commit is contained in:
parent
8430d735e7
commit
2db3088530
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user