Skip to content

Commit

Permalink
display boards
Browse files Browse the repository at this point in the history
  • Loading branch information
jwg4 committed Nov 11, 2023
1 parent bd4cc4f commit c100678
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions polyomino/board.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from pretty_poly import make_ascii

from .jupyter import board_to_png
from .problem import TilingProblem
from .tileset import exactly, many
from .transform import rotations
Expand Down Expand Up @@ -77,6 +78,9 @@ def format_tiling(self, pieces):
remainder = set(self.squares) - set(squares_in_pieces)
return make_ascii(pieces + [remainder])

def _repr_png_(self):
return board_to_png(self)


class Irregular(Shape):
_adjusted = None
Expand Down
11 changes: 10 additions & 1 deletion polyomino/jupyter.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import io

from pretty_poly.image import make_colored_blocks
from pretty_poly.image import make_colored_blocks, make_lines
from pretty_poly.png import _make_png_writer


def solution_to_png(solution):
data, palette = make_colored_blocks(solution.tiling)
writer = _make_png_writer(data, palette)
f = io.BytesIO()
writer.write(f, data)
return f.getvalue()


def board_to_png(board):
data, palette = make_lines([board.squares])
writer = _make_png_writer(data, palette)
f = io.BytesIO()
writer.write(f, data)
return f.getvalue()

0 comments on commit c100678

Please sign in to comment.