Skip to content

Commit

Permalink
Implement jupyter display for solutions.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwg4 committed Nov 11, 2023
1 parent 4c4b9c5 commit 2f67293
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions polyomino/jupyter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import io

from pretty_poly.image import make_colored_blocks
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()
5 changes: 5 additions & 0 deletions polyomino/solution.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from pretty_poly import make_ascii

from .jupyter import solution_to_png


class Solution(object):
def __init__(self, tiling, board):
Expand All @@ -14,3 +16,6 @@ def python(self):

def _gen_python(self):
yield "TILING = %s" % (repr(self.tiling),)

def _repr_png_(self):
return solution_to_png(self)

0 comments on commit 2f67293

Please sign in to comment.