Circular Maze Puzzle in MUI X Charts (JavaScript)

The same plot in 14 other libraries — JavaScript: Chart.js, D3.js, Apache ECharts, Highcharts; Python: Altair, Bokeh, lets-plot, Matplotlib, Plotly, plotnine, Pygal, Seaborn; R: ggplot2; Julia: Makie.jl. Compare all 15 side by side: Circular Maze Puzzle in Python, R, Julia and JavaScript.

A circular maze puzzle visualization featuring concentric rings connected by radial passages. Unlike rectangular mazes, this design creates a unique solving experience where the player navigates inward through ring-shaped corridors. The maze has an entry point on the outer edge and a goal at the center, with algorithmically generated walls ensuring exactly one solvable path.

Circular Maze Puzzle rendered with MUI X Charts

Renders

JavaScript source (MUI X Charts)

// anyplot.ai
// maze-circular: Circular Maze Puzzle
// Library: muix 9.17.0 | JavaScript 22.23.4
// Quality: 86/100 | Updated: 2026-11-08
//# anyplot-orientation: square
import { ChartsContainer } from "@mui/x-charts/ChartsContainer";
import { useXScale, useYScale } from "@mui/x-charts/hooks";

const t = window.ANYPLOT_TOKENS;

// Constants
// Difficulty sets how often the carve keeps extending the newest passage: a high share gives long
// winding corridors with few branch points (harder), a low one many short branches (easier).
// The carve is a spanning tree either way, so there is exactly one route between any two cells.
const DIFFICULTY_BIAS = { easy: 0.15, medium: 0.55, hard: 0.85 };
const MAZE_R = 1.04; // outer-wall radius plus its stroke, in outer-wall radii
const LABEL_R = 1.15; // radius of the START label anchor, just past the entry arrow
const LABEL_W = 70; // px width reserved for the START label
const LABEL_H = 26; // px height reserved for the START label
const GAP = 16; // px kept free around the drawing
const WALL_W = 3.5; // interior wall stroke in px
const OUTER_WALL_W = 5.5; // the outer boundary is drawn heavier
const GOAL_INK = "#1A1A17"; // the ink with the stronger contrast on the brand green goal disc

// Data: replace this block with your own parameters
const RINGS = 7; // role: rings
const DIFFICULTY = "medium"; // role: difficulty
const SEED = 42; // role: seed
const SECTORS = 12; // role: extra

// Plot: reads only the parameters and the constants above
// Cell graph: a hub at the centre, then RINGS rings of SECTORS cells; each edge is a wall that can be opened
const edges = [];
for (let s = 0; s < SECTORS; s += 1) edges.push({ a: "hub", b: `1-${s}`, key: `h-${s}` });
for (let r = 1; r <= RINGS; r += 1) {
  for (let s = 0; s < SECTORS; s += 1) edges.push({ a: `${r}-${s}`, b: `${r}-${(s + 1) % SECTORS}`, key: `c-${r}-${s}` });
}
for (let r = 1; r < RINGS; r += 1) {
  for (let s = 0; s < SECTORS; s += 1) edges.push({ a: `${r}-${s}`, b: `${r + 1}-${s}`, key: `r-${r}-${s}` });
}
const adjacency = new Map();
edges.forEach((e) => {
  [[e.a, e.b], [e.b, e.a]].forEach(([from, to]) => {
    if (!adjacency.has(from)) adjacency.set(from, []);
    adjacency.get(from).push({ from, to, key: e.key });
  });
});

// Randomised Prim's carve from the hub, biased by difficulty, with a fixed-seed LCG
const bias = DIFFICULTY_BIAS[DIFFICULTY];
const passages = new Set();
const visited = new Set(["hub"]);
const frontier = [...adjacency.get("hub")];
let lastAdded = "hub";
let state = SEED >>> 0;
while (frontier.length > 0) {
  state = (Math.imul(state, 1664525) + 1013904223) >>> 0;
  const continuing = state / 4294967296 < bias ? frontier.filter((e) => e.from === lastAdded) : [];
  const pool = continuing.length > 0 ? continuing : frontier;
  state = (Math.imul(state, 1664525) + 1013904223) >>> 0;
  const edge = pool[Math.floor((state / 4294967296) * pool.length)];
  frontier.splice(frontier.indexOf(edge), 1);
  if (visited.has(edge.to)) continue;
  visited.add(edge.to);
  lastAdded = edge.to;
  passages.add(edge.key);
  adjacency.get(edge.to).forEach((next) => {
    if (!visited.has(next.to)) frontier.push(next);
  });
}

// The entry is the outer cell farthest from the goal along the carved passages
const distance = new Map([["hub", 0]]);
const queue = ["hub"];
while (queue.length > 0) {
  const cell = queue.shift();
  adjacency.get(cell).forEach((e) => {
    if (passages.has(e.key) && !distance.has(e.to)) {
      distance.set(e.to, distance.get(cell) + 1);
      queue.push(e.to);
    }
  });
}
const entrySector = Array.from({ length: SECTORS }, (_, s) => s).reduce(
  (best, s) => (distance.get(`${RINGS}-${s}`) > distance.get(`${RINGS}-${best}`) ? s : best),
  0,
);
const routeCells = distance.get(`${RINGS}-${entrySector}`) + 1;

// Walls in unit-disc geometry: radius 1 is the outer wall, angle 0 points right, sectors run clockwise from 12 o'clock
const HUB_R = 1 / (RINGS + 1);
const RING_W = (1 - HUB_R) / RINGS;
const STEP = (2 * Math.PI) / SECTORS;
const walls = [];
for (let s = 0; s < SECTORS; s += 1) {
  if (!passages.has(`h-${s}`)) walls.push({ arc: true, r: HUB_R, a0: -Math.PI / 2 + s * STEP, width: WALL_W });
}
for (let r = 1; r <= RINGS; r += 1) {
  for (let s = 0; s < SECTORS; s += 1) {
    if (!passages.has(`c-${r}-${s}`)) {
      walls.push({ arc: false, r0: HUB_R + (r - 1) * RING_W, r1: HUB_R + r * RING_W, a0: -Math.PI / 2 + (s + 1) * STEP, width: WALL_W });
    }
    if (r < RINGS && !passages.has(`r-${r}-${s}`)) {
      walls.push({ arc: true, r: HUB_R + r * RING_W, a0: -Math.PI / 2 + s * STEP, width: WALL_W });
    }
  }
}
for (let s = 0; s < SECTORS; s += 1) {
  if (s !== entrySector) walls.push({ arc: true, r: 1, a0: -Math.PI / 2 + s * STEP, width: OUTER_WALL_W });
}
const entryAngle = -Math.PI / 2 + (entrySector + 0.5) * STEP;
const labelAnchor = Math.cos(entryAngle) > 0.3 ? "start" : Math.cos(entryAngle) < -0.3 ? "end" : "middle";

// Largest px-per-unit that fits the maze and the START label on one axis: the label sits at unit
// coordinate c and extends `before` px towards the negative side and `after` px towards the positive one
const fitUnit = (avail: number, c: number, before: number, after: number) =>
  Math.min(
    avail / (2 * MAZE_R),
    MAZE_R + c > 0 ? (avail - after) / (MAZE_R + c) : Infinity,
    MAZE_R - c > 0 ? (avail - before) / (MAZE_R - c) : Infinity,
  );
// View range on one axis: the content bounds at this scale, centred in the available span
const viewRange = (avail: number, unit: number, c: number, before: number, after: number) => {
  const lo = Math.min(-MAZE_R, c - before / unit);
  const hi = Math.max(MAZE_R, c + after / unit);
  const min = lo - (avail / unit - (hi - lo)) / 2;
  return { min, max: min + avail / unit };
};

const TITLE = "maze-circular · javascript · muix · anyplot.ai";
const SUBTITLE = `${RINGS} rings × ${SECTORS} sectors · ${DIFFICULTY} difficulty · seed ${SEED} · one ${routeCells}-cell route from START to GOAL`;
const HEADER_H = 92;

function Maze() {
  const xScale = useXScale();
  const yScale = useYScale();
  const unit = xScale(1) - xScale(0);
  const cx = xScale(0);
  const cy = yScale(0);
  const at = (r: number, a: number) => [cx + r * unit * Math.cos(a), cy + r * unit * Math.sin(a)];
  const [tipX, tipY] = at(1.025, entryAngle);
  const [leftX, leftY] = at(1.11, entryAngle - STEP * 0.07);
  const [rightX, rightY] = at(1.11, entryAngle + STEP * 0.07);
  // The label continues outward past the arrow, anchored away from the circle on whichever side the entry lies
  const [labelX, labelY] = at(LABEL_R, entryAngle);
  return (
    <g>
      {walls.map((w, i) => {
        const [x0, y0] = at(w.arc ? w.r : w.r0, w.a0);
        const [x1, y1] = w.arc ? at(w.r, w.a0 + STEP) : at(w.r1, w.a0);
        const d = w.arc ? `M ${x0} ${y0} A ${w.r * unit} ${w.r * unit} 0 0 1 ${x1} ${y1}` : `M ${x0} ${y0} L ${x1} ${y1}`;
        return <path key={i} d={d} fill="none" stroke={t.ink} strokeWidth={w.width} strokeLinecap="round" />;
      })}
      <path d={`M ${tipX} ${tipY} L ${leftX} ${leftY} L ${rightX} ${rightY} Z`} fill={t.palette[0]} />
      <text x={labelX} y={labelY} fontSize={20} fontWeight={700} fill={t.ink} textAnchor={labelAnchor} dominantBaseline="middle">
        START
      </text>
      <circle cx={cx} cy={cy} r={HUB_R * unit * 0.62} fill={t.palette[0]} />
      <text x={cx} y={cy} fontSize={18} fontWeight={700} fill={GOAL_INK} textAnchor="middle" dominantBaseline="central">
        GOAL
      </text>
    </g>
  );
}

export default function Chart() {
  const { width, height } = window.ANYPLOT_SIZE;
  const bodyH = height - HEADER_H;
  const availW = width - 2 * GAP;
  const availH = bodyH - 2 * GAP;
  // Only the side holding the START label gets extra room; one px-per-unit on both axes keeps the circle round
  const lx = LABEL_R * Math.cos(entryAngle);
  const ly = LABEL_R * Math.sin(entryAngle);
  const left = labelAnchor === "end" ? LABEL_W : labelAnchor === "middle" ? LABEL_W / 2 : 0;
  const right = labelAnchor === "start" ? LABEL_W : labelAnchor === "middle" ? LABEL_W / 2 : 0;
  const unit = Math.min(fitUnit(availW, lx, left, right), fitUnit(availH, ly, LABEL_H / 2, LABEL_H / 2));
  const xRange = viewRange(availW, unit, lx, left, right);
  const yRange = viewRange(availH, unit, ly, LABEL_H / 2, LABEL_H / 2);

  return (
    <div style={{ width, height, display: "flex", flexDirection: "column" }}>
      <div style={{ height: HEADER_H, padding: "18px 40px 0 40px", boxSizing: "border-box", textAlign: "center" }}>
        <div style={{ fontSize: 26, fontWeight: 600, color: t.ink, lineHeight: 1.25 }}>{TITLE}</div>
        <div style={{ fontSize: 18, color: t.inkSoft, marginTop: 6 }}>{SUBTITLE}</div>
      </div>
      <ChartsContainer
        width={width}
        height={bodyH}
        series={[]}
        skipAnimation
        margin={{ left: GAP, right: GAP, top: GAP, bottom: GAP }}
        xAxis={[{ id: "x", scaleType: "linear", ...xRange, position: "none" }]}
        yAxis={[{ id: "y", scaleType: "linear", ...yRange, reverse: true, position: "none" }]}
      >
        <Maze />
      </ChartsContainer>
    </div>
  );
}

Retrieve this implementation

Runnable source as JSON, for any HTTP client: https://api.anyplot.ai/specs/maze-circular/muix/code. Any spec id and library id listed in llms-full.txt fit the same URL shape; every URL below is complete and callable.

{
  "spec_id": "maze-circular",
  "language": "javascript",
  "library": "muix",
  "page": "https://anyplot.ai/maze-circular/javascript/muix",
  "hub": "https://anyplot.ai/maze-circular",
  "code_json": "https://api.anyplot.ai/specs/maze-circular/muix/code",
  "spec_json": "https://api.anyplot.ai/specs/maze-circular",
  "render_light_png": "https://storage.googleapis.com/anyplot-images/plots/maze-circular/javascript/muix/plot-light.png",
  "render_dark_png": "https://storage.googleapis.com/anyplot-images/plots/maze-circular/javascript/muix/plot-dark.png",
  "interactive_light_html": "https://storage.googleapis.com/anyplot-images/plots/maze-circular/javascript/muix/plot-light.html",
  "interactive_dark_html": "https://storage.googleapis.com/anyplot-images/plots/maze-circular/javascript/muix/plot-dark.html",
  "quality_score": 86.0,
  "license": "MIT",
  "guide": "https://anyplot.ai/llms.txt"
}

Part of Circular Maze Puzzle on anyplot.ai.

Other implementations