Skip to content

Commit

Permalink
Run black code linter
Browse files Browse the repository at this point in the history
  • Loading branch information
berinhard committed Sep 11, 2024
1 parent 25f6902 commit 9026aa3
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions be5/algorithms/wave_function_collapse.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def rotate(self, counter):
edges.rotate(counter)

return Tile(image=new_image, edges=edges)


@dataclass
class Cell:
i: int
Expand Down Expand Up @@ -91,6 +93,7 @@ def update_options(self, collapsed_cell):
cond = lambda tile: tile.right == ref_tile.left
self.options = list(filter(cond, self.options))


@dataclass
class WaveFunctionCollapseGrid:
tiles: list
Expand All @@ -113,7 +116,7 @@ def h(self):
def cells(self):
return [
Cell(i=i, j=j, options=self.tiles[:])
for i, j in product(range(0, py5.width // self.w), range(0, py5.height // self.h))
for i, j in product(range(0, py5.width // self.w), range(0, py5.height // self.h))
]

def start(self):
Expand All @@ -125,6 +128,7 @@ def collapse_cell(self, cell):
self.pending_cells.remove(cell)
for neighbor_cell in self.get_neighbors(cell):
neighbor_cell.update_options(collapsed_cell=cell)

def get_neighbors(self, cell):
i, j = cell.i, cell.j
positions = [
Expand All @@ -135,9 +139,7 @@ def get_neighbors(self, cell):
]

return [
c
for c in self.pending_cells
if all(((c.i == i or c.j == j), (c.i, c.j) in positions))
c for c in self.pending_cells if all(((c.i == i or c.j == j), (c.i, c.j) in positions))
]

@property
Expand All @@ -157,7 +159,10 @@ def draw(self):
py5.stroke(100)
py5.rect(cell.i * self.w, cell.j * self.h, self.w, self.h)


grid = None


def setup():
global grid
py5.size(800, 800)
Expand All @@ -179,6 +184,7 @@ def setup():
grid = WaveFunctionCollapseGrid(dim=40, tiles=tiles)
grid.start()


def draw():
grid.collapse()
grid.draw()
Expand All @@ -187,4 +193,5 @@ def draw():
print("finished!")
py5.no_loop()


py5.run_sketch()

0 comments on commit 9026aa3

Please sign in to comment.