notebookvb

This commit is contained in:
Vladimir Buzalka
2026-05-09 08:25:18 +02:00
parent c083e8e79a
commit 5bfd4176e4
30 changed files with 228 additions and 3105 deletions
@@ -57,6 +57,72 @@ def draw_str8ts(c: Canvas, x0: float, y0: float, puzzle: str, bw: str, title: st
c.line(x0 + i * CELL, y0, x0 + i * CELL, y0 - BOARD)
def _draw_sized(c: Canvas, x0: float, y0: float, cell: float,
puzzle: str, bw: str, title: str = ""):
grid = 9
board = grid * cell
font_size = cell * 0.55
if title:
c.setFont("Helvetica-Bold", 12)
c.drawString(x0, y0 + 5, title)
for idx in range(81):
row, col = divmod(idx, 9)
cell_x = x0 + col * cell
cell_y = y0 - (row + 1) * cell
is_black = bw[idx] == "1"
ch = puzzle[idx]
if is_black:
c.setFillColor(colors.black)
c.rect(cell_x, cell_y, cell, cell, fill=1, stroke=0)
if ch in "123456789":
c.setFillColor(colors.yellow if is_black else colors.black)
c.setFont("Helvetica-Bold", max(font_size, 4))
c.drawCentredString(cell_x + cell / 2, cell_y + cell * 0.3, ch)
c.setFillColor(colors.black)
for i in range(grid + 1):
c.setLineWidth(0.8)
c.line(x0, y0 - i * cell, x0 + board, y0 - i * cell)
c.line(x0 + i * cell, y0, x0 + i * cell, y0 - board)
def generate_pdf(puzzles: list[dict], output_path: Path):
"""puzzles: difficulty, puzzle, bw, solution, puzzle_date"""
BOARD_CM = 11
SOL_CM = 6
GAP = 1.5 * cm
page_w, page_h = A4
cell_main = BOARD_CM * cm / 9
board_main = 9 * cell_main
x0_main = (page_w - board_main) / 2
c = Canvas(str(output_path), pagesize=A4)
for i in range(0, len(puzzles), 2):
for j, p in enumerate(puzzles[i:i + 2]):
y0 = page_h - 2 * cm - j * (BOARD_CM * cm + 3 * cm)
_draw_sized(c, x0_main, y0, cell_main, p["puzzle"], p["bw"],
f"Str8ts {p['difficulty'].capitalize()}{p['puzzle_date']}")
c.showPage()
c.setFont("Helvetica-Bold", 14)
c.drawCentredString(page_w / 2, page_h - 2 * cm, "Řešení")
y_cursor = page_h - 3.5 * cm
sol_cell = SOL_CM * cm / 9
sol_board = 9 * sol_cell
x0_sol = (page_w - sol_board) / 2
for p in puzzles:
_draw_sized(c, x0_sol, y_cursor, sol_cell, p["solution"], p["bw"],
p["difficulty"].capitalize())
y_cursor -= sol_board + GAP
c.showPage()
c.save()
def main():
conn = connect_mysql(database="puzzle")
cur = conn.cursor()