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
@@ -126,6 +126,43 @@ def draw_suguru(c: Canvas, x0: float, y0: float, cell: float,
x0 + (co + 1) * cell, y0 - rows * cell)
def generate_pdf(puzzles: list[dict], output_path: Path):
"""puzzles: difficulty, puzzle_str, solution_str, grid_size, puzzle_date"""
BOARD_CM = 11
SOL_CM = 6
GAP = 1.5 * cm
page_w, page_h = A4
prepped = []
for p in puzzles:
color_map, clues, rows, cols = parse_puzzle(p["puzzle_str"], p["grid_size"])
solution = parse_solution(p["solution_str"], rows, cols)
cell = BOARD_CM * cm / max(rows, cols)
prepped.append((p, rows, cols, cell, color_map, clues, solution))
c = Canvas(str(output_path), pagesize=A4)
for i in range(0, len(prepped), 2):
for j, (p, rows, cols, cell, color_map, clues, _) in enumerate(prepped[i:i + 2]):
x0 = (page_w - cols * cell) / 2
y0 = page_h - 2 * cm - j * (BOARD_CM * cm + 3 * cm)
draw_suguru(c, x0, y0, cell, color_map, clues, rows, cols,
f"Suguru {p['difficulty']}{p['puzzle_date']}")
c.showPage()
c.setFont("ArialBold", 14)
c.drawCentredString(page_w / 2, page_h - 2 * cm, "Řešení")
y_cursor = page_h - 3.5 * cm
for p, rows, cols, _, color_map, clues, solution in prepped:
sol_cell = SOL_CM * cm / max(rows, cols)
x0 = (page_w - cols * sol_cell) / 2
draw_suguru(c, x0, y_cursor, sol_cell, color_map, clues, rows, cols,
p["difficulty"], solution=solution)
y_cursor -= rows * sol_cell + GAP
c.showPage()
c.save()
def main():
conn = connect_mysql(database="puzzle")
cur = conn.cursor()