Skip to content

Commit

Permalink
Merge pull request #10 from jameslawlor/chore/refactor-naming
Browse files Browse the repository at this point in the history
standardise turmite naming across repo
  • Loading branch information
jameslawlor authored Mar 30, 2024
2 parents 83b49a1 + 0e11177 commit ccaf357
Show file tree
Hide file tree
Showing 12 changed files with 168 additions and 168 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ https://github.com/jameslawlor/pyturmite/assets/3987960/072c9380-4971-4256-a6bf-

# Usage

Set run parameters in `src/langton_ant/constants.py`
Set run parameters in `src/pyturmite/constants.py`
```
pip install -r requirements.txt
pip install -e .
python src/langton_ant/main.py
python src/pyturmite/main.py
```
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
[project]
name = "langton-ant"
name = "pyturmite"
version = "0.0.1"
authors = [
{ name="James Lawlor", email="jameslawlor1987@gmail.com" },
]
description = "Langton's Ant"
description = "A package for generating turmites in Python"
readme = "README.md"
requires-python = ">=3.8"
requires-python = ">=3.12"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]

[project.urls]
Homepage = "https://github.com/jameslawlor/langton-ant"
Homepage = "https://github.com/jameslawlor/pyturmite"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.build.targets.wheel]
packages = ["src/langton_ant"]
packages = ["src/pyturmite"]

[tool.pytest.ini_options]
pythonpath = "src"
Expand Down
Empty file removed src/langton_ant/ants/__init__.py
Empty file.
17 changes: 0 additions & 17 deletions src/langton_ant/main.py

This file was deleted.

File renamed without changes.
File renamed without changes.
17 changes: 17 additions & 0 deletions src/pyturmite/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from pyturmite.turmites import Turmite
from pyturmite.utils.plotters import Plotter
from pyturmite.utils.input_handling import parse_args


def main():
args = parse_args()
turmite = Turmite()

turmite.init_grid(canvas_size=args.canvas_size)

plotter = Plotter()
plotter.plot(turmite=turmite, n_steps=args.n_steps, mode=args.plot_mode)


if __name__ == "__main__":
main()
6 changes: 3 additions & 3 deletions src/langton_ant/ants/langton.py → src/pyturmite/turmites.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import numpy as np
import matplotlib.pylab as plt
from langton_ant.constants import CMAP, RULESET
from pyturmite.constants import CMAP, RULESET

"""
The colors are modified in a cyclic fashion.
A simple naming scheme is used: for each of the successive colors,
a letter "L" or "R" is used to indicate whether a left or right turn
should be taken.
Langton's ant has the name "RL" in this naming scheme.
Langton's turmite has the name "RL" in this naming scheme.
"""


class LangtonAnt:
class Turmite:
def __init__(
self,
x0=0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import argparse
from langton_ant.constants import (
from pyturmite.constants import (
CANVAS_SIZE,
N_STEPS,
PLOT_MODE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,65 @@
import numpy as np
from matplotlib.animation import FuncAnimation
from functools import partial
from langton_ant.constants import ANIMATION_INTERVAL
from pyturmite.constants import ANIMATION_INTERVAL


class Plotter:
def __init__(self):
self.ant = None
self.turmite = None

def plot(self, ant, n_steps, mode):
def plot(self, turmite, n_steps, mode):
if mode == "static":
self.static_plot(ant, n_steps)
self.static_plot(turmite, n_steps)

elif mode == "animate":
self.animate(ant, n_steps)
self.animate(turmite, n_steps)

def static_plot(
self,
ant,
turmite,
N_STEPS,
):
for _ in range(N_STEPS):
ant.update()
turmite.update()

data = np.array(ant.grid)
data[ant.x][ant.y] = ant.n_colours + 1
data = np.array(turmite.grid)
data[turmite.x][turmite.y] = turmite.n_colours + 1
plt.figure()
plt.imshow(
data,
interpolation="none",
vmin=0,
vmax=ant.n_colours + 1,
cmap=ant.cmap,
vmax=turmite.n_colours + 1,
cmap=turmite.cmap,
)
plt.show()

def animate(self, ant, n_steps):
def animate(self, turmite, n_steps):
fig = plt.figure()

im = plt.imshow(
ant.grid,
turmite.grid,
interpolation="none",
vmin=0,
vmax=ant.n_colours + 1,
cmap=ant.cmap,
vmax=turmite.n_colours + 1,
cmap=turmite.cmap,
)
plt.axis("off")

def update(step, ant, skip=5):
def update(step, turmite, skip=5):
for _ in range(skip):
ant.update()
data = np.array(ant.grid)
data[ant.x][ant.y] = ant.n_colours + 1
turmite.update()
data = np.array(turmite.grid)
data[turmite.x][turmite.y] = turmite.n_colours + 1
im.set_data(data)
return [im]

anim = FuncAnimation( # noqa: F841
fig,
partial(
update,
ant=ant,
turmite=turmite,
),
frames=n_steps,
interval=ANIMATION_INTERVAL,
Expand Down
120 changes: 0 additions & 120 deletions tests/ants/test_langton.py

This file was deleted.

Loading

0 comments on commit ccaf357

Please sign in to comment.