{"spec_id":"maze-printable","library":"plotnine","language":"python","code":"\"\"\" anyplot.ai\nmaze-printable: Printable Maze Puzzle\nLibrary: plotnine 0.15.4 | Python 3.13.13\nQuality: 90/100 | Updated: 2026-05-16\n\"\"\"\n\nimport os\n\nimport numpy as np\nimport pandas as pd\nfrom plotnine import aes, coord_fixed, element_rect, element_text, geom_text, geom_tile, ggplot, labs, theme, theme_void\n\n\n# Theme tokens\nTHEME = os.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG = \"#FAF8F1\" if THEME == \"light\" else \"#1A1A17\"\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nBRAND = \"#009E73\"  # Okabe-Ito position 1\n\n# Maze generation using Depth-First Search (Recursive Backtracker)\nnp.random.seed(42)\nwidth, height = 25, 25\n\n# Initialize maze grid (all walls)\n# 0 = passage, 1 = wall\nmaze = np.ones((height * 2 + 1, width * 2 + 1), dtype=int)\n\n# Starting cell (top-left)\nstart_cell = (1, 1)\nmaze[start_cell[0], start_cell[1]] = 0\n\n# DFS maze generation\nstack = [start_cell]\nvisited = {start_cell}\n\nwhile stack:\n    current = stack[-1]\n    cy, cx = current\n\n    # Find unvisited neighbors (2 cells away)\n    neighbors = []\n    for dy, dx in [(-2, 0), (2, 0), (0, -2), (0, 2)]:\n        ny, nx = cy + dy, cx + dx\n        if 1 <= ny < height * 2 and 1 <= nx < width * 2:\n            if (ny, nx) not in visited:\n                neighbors.append((ny, nx, dy // 2, dx // 2))\n\n    if neighbors:\n        # Choose random neighbor\n        ny, nx, wy, wx = neighbors[np.random.randint(len(neighbors))]\n        # Remove wall between current and neighbor\n        maze[cy + wy, cx + wx] = 0\n        maze[ny, nx] = 0\n        visited.add((ny, nx))\n        stack.append((ny, nx))\n    else:\n        stack.pop()\n\n# Create DataFrame for plotting\nrows = []\nfor y in range(maze.shape[0]):\n    for x in range(maze.shape[1]):\n        if maze[y, x] == 1:  # Wall\n            rows.append({\"x\": x, \"y\": -y, \"type\": \"wall\"})\n\nwalls_df = pd.DataFrame(rows)\n\n# Start and goal positions\nstart_y, start_x = 1, 1\ngoal_y, goal_x = height * 2 - 1, width * 2 - 1\n\nmarkers_df = pd.DataFrame(\n    {\"x\": [start_x, goal_x], \"y\": [-start_y, -goal_y], \"label\": [\"S\", \"G\"], \"type\": [\"marker\", \"marker\"]}\n)\n\n# Create the plot\nplot = (\n    ggplot()\n    + geom_tile(data=walls_df, mapping=aes(x=\"x\", y=\"y\"), fill=INK, width=1, height=1)\n    + geom_text(data=markers_df, mapping=aes(x=\"x\", y=\"y\", label=\"label\"), size=48, color=BRAND)\n    + coord_fixed(ratio=1)\n    + labs(title=\"maze-printable · plotnine · anyplot.ai\")\n    + theme_void()\n    + theme(\n        figure_size=(12, 12),\n        plot_title=element_text(size=24, ha=\"center\", weight=\"bold\", color=INK),\n        plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG),\n        panel_background=element_rect(fill=PAGE_BG, color=PAGE_BG),\n    )\n)\n\n# Save\nplot.save(f\"plot-{THEME}.png\", dpi=300)\n"}