{"spec_id":"maze-printable","library":"bokeh","language":"python","code":"\"\"\" anyplot.ai\nmaze-printable: Printable Maze Puzzle\nLibrary: bokeh 3.9.0 | Python 3.13.13\nQuality: 71/100 | Updated: 2026-05-16\n\"\"\"\n\nimport numpy as np\nfrom bokeh.io import export_png\nfrom bokeh.plotting import figure, output_file, save\n\n\n# Maze generation using DFS (guarantees single solution)\nnp.random.seed(42)\nwidth, height = 25, 25\n\n# Initialize maze grid (0 = wall, 1 = passage)\nmaze = np.zeros((height * 2 + 1, width * 2 + 1), dtype=int)\n\n# DFS maze generation\nvisited = np.zeros((height, width), dtype=bool)\nstack = [(0, 0)]\nvisited[0, 0] = True\nmaze[1, 1] = 1\n\ndirections = [(0, 1), (1, 0), (0, -1), (-1, 0)]\n\nwhile stack:\n    cy, cx = stack[-1]\n    neighbors = []\n    for dy, dx in directions:\n        ny, nx = cy + dy, cx + dx\n        if 0 <= ny < height and 0 <= nx < width and not visited[ny, nx]:\n            neighbors.append((ny, nx, dy, dx))\n\n    if neighbors:\n        ny, nx, dy, dx = neighbors[np.random.randint(len(neighbors))]\n        visited[ny, nx] = True\n        maze[cy * 2 + 1 + dy, cx * 2 + 1 + dx] = 1\n        maze[ny * 2 + 1, nx * 2 + 1] = 1\n        stack.append((ny, nx))\n    else:\n        stack.pop()\n\n# Collect wall segments\nwall_xs = []\nwall_ys = []\nwall_widths = []\nwall_heights = []\n\ncell_size = 80\nwall_thickness = 8\n\nmaze_h, maze_w = maze.shape\n\nfor row in range(maze_h):\n    for col in range(maze_w):\n        if maze[row, col] == 0:\n            x = col * cell_size\n            y = (maze_h - 1 - row) * cell_size\n            wall_xs.append(x + cell_size / 2)\n            wall_ys.append(y + cell_size / 2)\n            wall_widths.append(cell_size + wall_thickness / 2)\n            wall_heights.append(cell_size + wall_thickness / 2)\n\n# Create figure with small margin for the outer wall\ntotal_w = maze_w * cell_size\ntotal_h = maze_h * cell_size\nmargin = cell_size / 2  # Small margin to show outer wall\n\np = figure(\n    width=4800,\n    height=4800,\n    title=\"maze-printable · bokeh · pyplots.ai\",\n    x_range=(-margin, total_w + margin),\n    y_range=(-margin, total_h + margin),\n    tools=\"\",\n    toolbar_location=None,\n    match_aspect=True,\n)\n\n# White background\np.background_fill_color = \"white\"\np.border_fill_color = \"white\"\np.outline_line_color = None\n\n# Hide axes and grid\np.xaxis.visible = False\np.yaxis.visible = False\np.xgrid.visible = False\np.ygrid.visible = False\n\n# Draw walls as rectangles\np.rect(x=wall_xs, y=wall_ys, width=wall_widths, height=wall_heights, fill_color=\"#000000\", line_color=None)\n\n# Start/Goal markers at first and last passage cells\nstart_col, start_row = 1, 1\nend_col, end_row = maze_w - 2, maze_h - 2\n\nstart_x = start_col * cell_size + cell_size / 2\nstart_y = (maze_h - 1 - start_row) * cell_size + cell_size / 2\ngoal_x = end_col * cell_size + cell_size / 2\ngoal_y = (maze_h - 1 - end_row) * cell_size + cell_size / 2\n\n# Draw markers with labels\np.scatter([start_x], [start_y], size=55, fill_color=\"#306998\", line_color=\"white\", line_width=4, marker=\"circle\")\np.scatter([goal_x], [goal_y], size=55, fill_color=\"#FFD43B\", line_color=\"#333333\", line_width=4, marker=\"circle\")\n\np.text(\n    [start_x],\n    [start_y],\n    text=[\"S\"],\n    text_font_size=\"28pt\",\n    text_font_style=\"bold\",\n    text_color=\"white\",\n    text_align=\"center\",\n    text_baseline=\"middle\",\n)\np.text(\n    [goal_x],\n    [goal_y],\n    text=[\"G\"],\n    text_font_size=\"28pt\",\n    text_font_style=\"bold\",\n    text_color=\"#333333\",\n    text_align=\"center\",\n    text_baseline=\"middle\",\n)\n\n# Title styling\np.title.text_font_size = \"36pt\"\np.title.text_color = \"#333333\"\np.title.align = \"center\"\n\n# Save outputs\nexport_png(p, filename=\"plot.png\")\noutput_file(\"plot.html\")\nsave(p)\n"}