Fix/dead pixel lines
This commit is contained in:
parent
19be460edc
commit
acbda2bcf2
@ -98,6 +98,9 @@ There ist still quite some work to do.
|
||||
And for all others, don't hesitate to open issues when you have problems!
|
||||
|
||||
## Changelog
|
||||
#### 1.0.5
|
||||
- Fixes black lines in the display between some cell lines/columns
|
||||
|
||||
#### 1.0.4
|
||||
- Adds active state for automaton
|
||||
- Adds reactivation method
|
||||
|
@ -46,7 +46,7 @@ class PygameEngine:
|
||||
self._height = window_size[1]
|
||||
|
||||
def write_text(self, pos, text, color=(0, 255, 0)):
|
||||
label = self.__font.render(text, 1, color)
|
||||
label = self.__font.render(text, True, color)
|
||||
update_rect = self.__screen.blit(label, pos)
|
||||
self.update_rectangles(update_rect)
|
||||
|
||||
@ -67,6 +67,7 @@ class CAWindow:
|
||||
def __init__(self,
|
||||
cellular_automaton: CellularAutomaton,
|
||||
window_size=(1000, 800),
|
||||
stretch_cells=False,
|
||||
draw_engine=None,
|
||||
state_to_color_cb=None,
|
||||
*args, **kwargs):
|
||||
@ -74,13 +75,15 @@ class CAWindow:
|
||||
Creates a window to render a 2D CellularAutomaton.
|
||||
:param cellular_automaton: The automaton to display and evolve
|
||||
:param window_size: The Window size (default: 1000 x 800)
|
||||
:param stretch_cells: Stretches cells to fit into window size. (default: false)
|
||||
Activating it can result in black lines throughout the automaton.
|
||||
:param draw_engine: The draw_engine (default: pygame)
|
||||
: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 = cellular_automaton
|
||||
self.__rect = _Rect(left=0, top=30, width=window_size[0], height=window_size[1] - 30)
|
||||
self.__calculate_cell_display_size()
|
||||
self.__calculate_cell_display_size(stretch_cells)
|
||||
self.__draw_engine = PygameEngine(window_size) if draw_engine is None else draw_engine
|
||||
self.__state_to_color = self._get_cell_color if state_to_color_cb is None else state_to_color_cb
|
||||
|
||||
@ -116,9 +119,14 @@ class CAWindow:
|
||||
def _not_at_the_end(self, last_evolution_step):
|
||||
return self._cellular_automaton.evolution_step < last_evolution_step or last_evolution_step <= 0
|
||||
|
||||
def __calculate_cell_display_size(self):
|
||||
def __calculate_cell_display_size(self, stretch_cells): # pragma: no cover
|
||||
grid_dimension = self._cellular_automaton.dimension
|
||||
self.__cell_size = [self.__rect.width / grid_dimension[0], self.__rect.height / grid_dimension[1]]
|
||||
if stretch_cells:
|
||||
self.__cell_size = [self.__rect.width / grid_dimension[0],
|
||||
self.__rect.height / grid_dimension[1]]
|
||||
else:
|
||||
self.__cell_size = [int(self.__rect.width / grid_dimension[0]),
|
||||
int(self.__rect.height / grid_dimension[1])]
|
||||
|
||||
def _redraw_dirty_cells(self):
|
||||
self.__draw_engine.update_rectangles(list(self.__redraw_dirty_cells()))
|
||||
|
@ -64,4 +64,5 @@ class ConwaysCA(CellularAutomaton):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
CAWindow(cellular_automaton=ConwaysCA()).run(evolutions_per_second=40)
|
||||
CAWindow(cellular_automaton=ConwaysCA(),
|
||||
window_size=(1000, 830)).run(evolutions_per_second=40)
|
||||
|
@ -33,7 +33,7 @@ class StarFallAutomaton(CellularAutomaton):
|
||||
""" Represents an automaton dropping colorful stars """
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(dimension=[100, 100],
|
||||
super().__init__(dimension=[200, 200],
|
||||
neighborhood=MooreNeighborhood(EdgeRule.FIRST_AND_LAST_CELL_OF_DIMENSION_ARE_NEIGHBORS))
|
||||
|
||||
def init_cell_state(self, __) -> Sequence:
|
||||
@ -52,4 +52,6 @@ def state_to_color(current_state: Sequence) -> Sequence:
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
CAWindow(cellular_automaton=StarFallAutomaton(), state_to_color_cb=state_to_color).run()
|
||||
CAWindow(cellular_automaton=StarFallAutomaton(),
|
||||
window_size=(1000, 830),
|
||||
state_to_color_cb=state_to_color).run()
|
||||
|
Loading…
Reference in New Issue
Block a user