diff --git a/pyproject.toml b/pyproject.toml index 2543c7a..f01f63b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,10 +18,14 @@ classifiers = [ ] [project.urls] -"Homepage" = "https://git.weber.codes/tom/gameoflife" -"Bug Tracker" = "https://git.weber.codes/tom/gameoflife/issues" +"repository" = "https://git.weber.codes/tom/gameoflife" [tool.pytest.ini_options] addopts = [ "--import-mode=importlib", -] \ No newline at end of file +] + +dependencies = [ +"numpy>=1.23.3", +"plotly==5.11.0" + ] \ No newline at end of file diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index b1da47c..0000000 --- a/requirements.txt +++ /dev/null @@ -1,15 +0,0 @@ -contourpy==1.0.5 -cycler==0.11.0 -fonttools==4.37.4 -kiwisolver==1.4.4 -matplotlib==3.6.0 -numpy==1.23.3 -packaging==21.3 -pandas==1.5.1 -Pillow==9.2.0 -plotly==5.11.0 -pyparsing==3.0.9 -python-dateutil==2.8.2 -pytz==2022.6 -six==1.16.0 -tenacity==8.1.0 diff --git a/src/conway/anime.py b/src/conway/anime.py index 6484bbc..7bd9a8a 100644 --- a/src/conway/anime.py +++ b/src/conway/anime.py @@ -1,10 +1,6 @@ -import matplotlib.animation as animation -import matplotlib.pyplot as plt -#import plotly.graph_objects as go import plotly.express as px import numpy as np - class PlotlyAnimation(object): def __init__(self, state, steps): self.state = state @@ -19,7 +15,7 @@ class PlotlyAnimation(object): return self.frames def animation_gen(self): - fig = px.imshow(self.frames, animation_frame=0) + fig = px.imshow(self.frames, animation_frame=0, color_continuous_scale=[[0, "white"], [1, "black"]]) fig.layout.updatemenus[0].buttons[0].args[1]['frame']['duration'] = 30 fig.layout.updatemenus[0].buttons[0].args[1]['transition']['duration'] = 5 fig.layout.updatemenus[0].showactive = True @@ -31,49 +27,3 @@ class PlotlyAnimation(object): def show(self): self.animation.show() - - -class PltAnimation(object): - def __init__(self, state, steps=None): - - self.state = state - self.steps = steps - self.fig, self.ax = plt.subplots() - self.ax = self.ax.matshow(self.state.board) - - def frame_yield(self): - while True: - self.state.step() - yield self.state.board - - def frame_gen(self): - frames = [] - for i in range(self.steps): - self.state.step() - [].append(self.state.board) - return self.ax, frames - - def init(self): - return self.state.board - - def update(self, data): - self.ax.set_data(data) - return self.ax - - def animate(self): - if self.steps is None: - return animation.FuncAnimation( - self.fig, - self.update, - self.frame_yield, - init_func=self.init, - interval=100, - ) - else: - return animation.FuncAnimation( - self.fig, - self.update, - self.frame_gen, - init_func=self.init, - interval=100, - ) diff --git a/src/conway/gameoflife.py b/src/conway/gameoflife.py index e31bdb7..9955b74 100644 --- a/src/conway/gameoflife.py +++ b/src/conway/gameoflife.py @@ -1,7 +1,6 @@ #!/usr/bin/env python import copy -import matplotlib.pyplot as plt import numpy as np from conway.anime import PlotlyAnimation @@ -103,15 +102,14 @@ def get_starting_board(size, start="random"): else: return State(size, size, None) -def get(size = 100, start="random"): +def get(size = 507, steps = 200, start="random"): board = get_starting_board(size, start) - return PlotlyAnimation(board, size).animation + return PlotlyAnimation(board, steps).animation def main(): - state = State(100, 100, "random") - animation = PlotlyAnimation(state, 100) + animation = get(50) animation.show() if __name__ == "__main__": - main() + main() \ No newline at end of file