Skip to content

Commit

Permalink
Update sketch_2024_12_11.py
Browse files Browse the repository at this point in the history
  • Loading branch information
villares committed Dec 12, 2024
1 parent 90994a1 commit 2b0e95c
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions 2024/sketch_2024_12_11/sketch_2024_12_11.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def draw():
py5.background(200)
py5.translate(Grid.CS, Grid.CS)
x = y = 0
for g in grids:
#for g in set(grids): # to test duplicate removal
for g in set(grids):
with py5.push_matrix():
py5.translate(x, y)
g.draw()
Expand Down Expand Up @@ -57,7 +58,25 @@ def rot90(a):
This will have more stuff later...
... it will need to roll the sub-elements
"""
return np.rot90(a)
return np.rot90(a, 1)

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

def __hash__(self):
"""
Makes rotations and different colors equivalent.
"""
a = self.array
h = hash(a.tobytes())
values, inverse_indices = np.unique(a, return_inverse=True)
for vs in permutations(values):
a = np.array(vs)[inverse_indices].reshape(self.shape)
h = min(h, hash(a.tobytes()))
for _ in range(3):
a = self.rot90(a)
h = min(h, hash(a.tobytes()))
return h

def draw(self):
rows, cols, subelements = self.array.shape
Expand Down

0 comments on commit 2b0e95c

Please sign in to comment.