From 68ac0362033db5bd8511f65add66020bce8c7217 Mon Sep 17 00:00:00 2001 From: Richard Feistenauer Date: Sat, 5 Jan 2019 15:45:09 +0100 Subject: [PATCH] increased set state speed --- scripts/main_ui.py | 2 +- src/cellular_automaton/ca_cell_state.py | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/scripts/main_ui.py b/scripts/main_ui.py index 0d5b4ba..fb374c7 100644 --- a/scripts/main_ui.py +++ b/scripts/main_ui.py @@ -35,7 +35,7 @@ class MyStatus(CellState): def get_state_draw_color(self, iteration): red = 0 - if self._state[iteration % 2][0]: + if self._state_slots[iteration % 2][0]: red = 255 return [red, 0, 0] diff --git a/src/cellular_automaton/ca_cell_state.py b/src/cellular_automaton/ca_cell_state.py index 2ffebcb..68ff325 100644 --- a/src/cellular_automaton/ca_cell_state.py +++ b/src/cellular_automaton/ca_cell_state.py @@ -5,7 +5,7 @@ class CellState: """ def __init__(self, initial_state, state_save_slot_count=2): self._state_save_slot_count = state_save_slot_count - self._state = [[initial_state]] * state_save_slot_count + self._state_slots = [[initial_state]] * state_save_slot_count def set_status_of_iteration(self, new_status, iteration): """ Will set the new status for the iteration modulo number of saved states. @@ -13,17 +13,20 @@ class CellState: :param iteration: Uses the iteration index, to differ between concurrent states. :return True if status has changed. """ - self._state[iteration % self._state_save_slot_count] = new_status + slot_count = self._state_save_slot_count + states = self._state_slots - return self._state[(iteration - 1) % self._state_save_slot_count] \ - != self._state[iteration % self._state_save_slot_count] + states[iteration % slot_count] = new_status + + return states[(iteration - 1) % slot_count] \ + != states[iteration % slot_count] def get_status_of_iteration(self, iteration): """ Will return the status for the iteration modulo number of saved states. :param iteration: Uses the iteration index, to differ between concurrent states. :return The status for this iteration. """ - return self._state[iteration % self._state_save_slot_count] + return self._state_slots[iteration % self._state_save_slot_count] def get_state_draw_color(self, iteration): raise NotImplementedError