diff --git a/.gitignore b/.gitignore index bce6882..9784317 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ __pycache__ .coverage htmlcov/ -*.orig \ No newline at end of file +*.orig +performance.txt \ No newline at end of file diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..e69de29 diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..bd133bb --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +recursive-include cellular_automaton/examples * \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..79356a6 --- /dev/null +++ b/__init__.py @@ -0,0 +1 @@ +from .cellular_automaton import * \ No newline at end of file diff --git a/cellular_automaton/__init__.py b/cellular_automaton/__init__.py new file mode 100644 index 0000000..aa0e537 --- /dev/null +++ b/cellular_automaton/__init__.py @@ -0,0 +1,6 @@ +from .cell_state import * +from .neighborhood import * +from .rule import * +from .factory import * +from .automaton import * +from .display import * diff --git a/src/cellular_automaton/ca_cell.py b/cellular_automaton/_cell.py similarity index 94% rename from src/cellular_automaton/ca_cell.py rename to cellular_automaton/_cell.py index e42e886..ff487b5 100644 --- a/src/cellular_automaton/ca_cell.py +++ b/cellular_automaton/_cell.py @@ -1,4 +1,4 @@ -from cellular_automaton.ca_cell_state import CellState +from .cell_state import CellState from typing import Type diff --git a/src/cellular_automaton/ca_state.py b/cellular_automaton/_state.py similarity index 83% rename from src/cellular_automaton/ca_state.py rename to cellular_automaton/_state.py index ac5f789..e5792e7 100644 --- a/src/cellular_automaton/ca_state.py +++ b/cellular_automaton/_state.py @@ -1,4 +1,4 @@ -from cellular_automaton.ca_rule import Rule +from cellular_automaton.cellular_automaton import Rule from typing import Type diff --git a/src/cellular_automaton/cellular_automaton.py b/cellular_automaton/automaton.py similarity index 100% rename from src/cellular_automaton/cellular_automaton.py rename to cellular_automaton/automaton.py diff --git a/src/cellular_automaton/ca_cell_state.py b/cellular_automaton/cell_state.py similarity index 100% rename from src/cellular_automaton/ca_cell_state.py rename to cellular_automaton/cell_state.py diff --git a/src/cellular_automaton/ca_display.py b/cellular_automaton/display.py similarity index 96% rename from src/cellular_automaton/ca_display.py rename to cellular_automaton/display.py index 1982786..505c24e 100644 --- a/src/cellular_automaton/ca_display.py +++ b/cellular_automaton/display.py @@ -7,8 +7,7 @@ import pstats from pympler import asizeof -from cellular_automaton.ca_state import CellularAutomatonState -from cellular_automaton.cellular_automaton import CellularAutomatonProcessor +from . import CellularAutomatonState, CellularAutomatonProcessor class _DisplayInfo: diff --git a/src/cellular_automaton/ca_factory.py b/cellular_automaton/factory.py similarity index 90% rename from src/cellular_automaton/ca_factory.py rename to cellular_automaton/factory.py index ce2f9fa..fdb5679 100644 --- a/src/cellular_automaton/ca_factory.py +++ b/cellular_automaton/factory.py @@ -1,4 +1,6 @@ -from cellular_automaton import * +from . import Neighborhood, CellState, Rule +from ._cell import Cell +from ._state import CellularAutomatonState from typing import Type import itertools diff --git a/src/cellular_automaton/ca_neighborhood.py b/cellular_automaton/neighborhood.py similarity index 100% rename from src/cellular_automaton/ca_neighborhood.py rename to cellular_automaton/neighborhood.py diff --git a/src/cellular_automaton/ca_rule.py b/cellular_automaton/rule.py similarity index 87% rename from src/cellular_automaton/ca_rule.py rename to cellular_automaton/rule.py index aa744ab..799b21b 100644 --- a/src/cellular_automaton/ca_rule.py +++ b/cellular_automaton/rule.py @@ -11,7 +11,7 @@ class Rule: """ Calculates and sets new state of 'cell'. :param last_cell_state: The cells current state to calculate new state for. :param neighbors_last_states: The cells neighbors current states. - :return: True if state changed, False if not. + :return: New state. A cells evolution will only be called if it or at least one of its neighbors has changed last evolution_step cycle. """ - return False + return last_cell_state diff --git a/scripts/main_ui.py b/examples/basic_2d_ca.py similarity index 90% rename from scripts/main_ui.py rename to examples/basic_2d_ca.py index ad3e26e..5344735 100644 --- a/scripts/main_ui.py +++ b/examples/basic_2d_ca.py @@ -1,8 +1,7 @@ #!/usr/bin/env python3 import random -from cellular_automaton.ca_rule import Rule -from cellular_automaton.ca_cell_state import CellState, SynchronousCellState +from cellular_automaton import * class TestRule(Rule): @@ -29,7 +28,6 @@ class MyState(CellState): if __name__ == "__main__": - from cellular_automaton import * # best single is 400/400 with 0,2 ca speed and 0,09 redraw / multi is 300/300 with 0.083 neighborhood = MooreNeighborhood(EdgeRule.FIRST_AND_LAST_CELL_OF_DIMENSION_ARE_NEIGHBORS) ca = CAFactory.make_cellular_automaton(dimension=[100, 100], diff --git a/images/map.png b/images/map.png deleted file mode 100644 index b18b217..0000000 Binary files a/images/map.png and /dev/null differ diff --git a/scripts/performance_test b/scripts/performance_test deleted file mode 100644 index e7286fe..0000000 Binary files a/scripts/performance_test and /dev/null differ diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..6977244 --- /dev/null +++ b/setup.py @@ -0,0 +1,14 @@ +from distutils.core import setup + +setup( + name="cellular_automaton", + version="0.1.0", + author="Richard Feistenauer", + author_email="r.feistenauer@web.de", + packages=["cellular_automaton"], + url="https://gitlab.com/DamKoVosh/cellular_automaton", + license="LICENSE.txt", + description="N dimensional cellular automaton implementation with multi processing capability.", + long_description="README.md", + requires=["pygame"] +) diff --git a/src/cellular_automaton/__init__.py b/src/cellular_automaton/__init__.py deleted file mode 100644 index c5cd890..0000000 --- a/src/cellular_automaton/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -from .ca_cell import * -from .ca_cell_state import * -from .ca_display import * -from .ca_neighborhood import * -from .ca_rule import * -from .ca_state import * -from .cellular_automaton import * -from .ca_factory import * diff --git a/test/test_cell.py b/test/test_cell.py index 1ff3996..9b6d439 100644 --- a/test/test_cell.py +++ b/test/test_cell.py @@ -1,7 +1,7 @@ import sys sys.path.append('../src') -from cellular_automaton import * +from cellular_automaton.cellular_automaton import * import unittest diff --git a/test/test_cell_state.py b/test/test_cell_state.py index 42b802a..30f3396 100644 --- a/test/test_cell_state.py +++ b/test/test_cell_state.py @@ -1,7 +1,7 @@ import sys sys.path.append('../src') -import cellular_automaton.ca_cell_state as cs +from cellular_automaton import cellular_automaton as cs import unittest diff --git a/test/test_factory.py b/test/test_factory.py index 7558110..116e8ac 100644 --- a/test/test_factory.py +++ b/test/test_factory.py @@ -1,7 +1,7 @@ import sys sys.path.append('../src') -from cellular_automaton import * +from cellular_automaton.cellular_automaton import * import unittest import mock diff --git a/test/test_neighborhood.py b/test/test_neighborhood.py index fde97a5..6241672 100644 --- a/test/test_neighborhood.py +++ b/test/test_neighborhood.py @@ -1,7 +1,7 @@ import sys sys.path.append('../src') -import cellular_automaton.ca_neighborhood as csn +from cellular_automaton import cellular_automaton as csn import unittest