Last active
March 11, 2018 06:45
-
-
Save ChristopherKing42/14c823ef16f32ed468ea8cb80ce0e154 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
move = False | |
rotate = True | |
def hyperbolicTiling(n_sides, n_order): | |
assert 1/2 + 1/n_sides + 1/n_order < 1 | |
class tiling(object): | |
sides = n_sides | |
order = n_order | |
def __init__(self, cell = ()): | |
#todo: use Aho-Corasick algorithm | |
cell = list(cell) | |
i = 0 | |
while i < len(cell): | |
if cell[i:i+2] == [move, move]: | |
cell[i:i+2] = [] | |
elif cell[i:i+tiling.sides] == [rotate] * tiling.sides: | |
cell[i:i+tiling.sides] = [] | |
elif cell[i:i+2*tiling.order] == [rotate,move] * tiling.order: | |
cell[i:i+2*tiling.order] = [] | |
else: | |
i += 1 | |
self.__cell = tuple(cell) | |
@property | |
def cell(self): | |
return self.__cell | |
def __repr__(self): | |
rep = "" | |
for c in self.cell: | |
if c: rep += 'R' | |
else: rep += 'M' | |
if rep == "": rep = "<origin>" | |
return rep | |
def __eq__(self,other): | |
assert type(self) == type(other), "tiling.__eq__: must be from the same tiling" | |
return self.cell == other.cell | |
def sameCell(self,other): | |
assert type(self) == type(other), "tiling.__sameCell__: must be from the same tiling" | |
return self in [other.rotated(i) for i in xrange(tiling.sides)] | |
def moved(self): | |
return tiling((move,) + self.cell) | |
def rotated(self,steps=1): | |
return tiling(((rotate,) * (steps % tiling.sides)) + self.cell) | |
#todo: position of center of cell and position of endpoints of edge in some model of hyperbolic geometry | |
return tiling |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment