Skip to content

Commit

Permalink
Update sketch_2024_12_10.py
Browse files Browse the repository at this point in the history
  • Loading branch information
villares committed Dec 11, 2024
1 parent efd3f25 commit f94fca7
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion 2024/sketch_2024_12_10/sketch_2024_12_10.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def setup():
grids.append(grids[-1].rotated90())
#grids.append(grids[-1].alternate())

#for g in set(grids):
for g in grids:
g.draw()
py5.translate(Grid.CS * (g.order + 1), 0)
Expand All @@ -38,6 +39,19 @@ def rotated90(self):
def alternate(self):
return Grid((self.array + 1) % len(self.colors), order=self.order)

def __eq__(self, other):
return hash(self) == hash(other)

def __hash__(self):
"""
Makes rotations equivalent.
"""
h = hash(self.array.tobytes())
s = self
for _ in range(3):
s = s.rotated90()
h = min(h, hash(s.array.tobytes()))
return(h)

def draw(self):
rows, cols = self.array.shape
Expand All @@ -49,5 +63,4 @@ def draw(self):
py5.square(x, y, self.CS)



py5.run_sketch(block=False)

0 comments on commit f94fca7

Please sign in to comment.