{"spec_id":"heatmap-mandelbrot","library":"makie","language":"julia","code":"# anyplot.ai\n# heatmap-mandelbrot: Mandelbrot Set Fractal Visualization\n# Library: makie 0.24.16 | Julia 1.13.4\n# Quality: 86/100 | Updated: 2026-11-28\n\nusing CairoMakie\nusing Colors\n\n# Theme tokens (Imprint palette — theme-adaptive chrome)\nconst THEME       = get(ENV, \"ANYPLOT_THEME\", \"light\")\nconst PAGE_BG     = THEME == \"light\" ? colorant\"#FAF8F1\" : colorant\"#1A1A17\"\nconst INK         = THEME == \"light\" ? colorant\"#1A1A17\" : colorant\"#F0EFE8\"\nconst INK_SOFT    = THEME == \"light\" ? colorant\"#4A4A44\" : colorant\"#B8B7B0\"\n\n# Imprint sequential colormap, fields stops (colored cells fill the plot)\nconst ANYPLOT_SEQ_FIELDS = THEME == \"light\" ?\n    cgrad([colorant\"#66E2B2\", colorant\"#009E73\", colorant\"#024582\", colorant\"#351E45\"], [0.0, 0.369, 0.803, 1.0]) :\n    cgrad([colorant\"#404C02\", colorant\"#009E73\", colorant\"#CDD9FF\"], [0.0, 0.487, 1.0])\n\n# Interior of the Mandelbrot set: near-black (canonical convention, never escapes)\nconst INTERIOR_COLOR = colorant\"#0A0A0A\"\n\n# Mandelbrot parameters\nconst X_MIN    = -2.5\nconst X_MAX    =  1.0\nconst Y_MIN    = -1.25\nconst Y_MAX    =  1.25\nconst MAX_ITER = 256\nconst BAILOUT_SQ = 256.0^2   # large bailout radius keeps the smooth count free of arcs\nconst TICK_COUNTS = [2, 4, 8, 16, 32, 64, 128, 256]\nconst WIDTH    = 1600\nconst HEIGHT   =  900\n\n# Compute smooth escape count for each pixel\nxs = range(X_MIN, X_MAX; length = WIDTH)\nys = range(Y_MIN, Y_MAX; length = HEIGHT)\nescape = Matrix{Float64}(undef, WIDTH, HEIGHT)\n\nfor i in 1:WIDTH, j in 1:HEIGHT\n    cx = xs[i]\n    cy = ys[j]\n    zx = 0.0\n    zy = 0.0\n    iter = 0\n    escaped = false\n    while iter < MAX_ITER\n        zx2 = zx * zx\n        zy2 = zy * zy\n        if zx2 + zy2 > BAILOUT_SQ\n            escaped = true\n            break\n        end\n        zy = 2.0 * zx * zy + cy\n        zx = zx2 - zy2 + cx\n        iter += 1\n    end\n    if escaped\n        zmod = sqrt(zx * zx + zy * zy)\n        smooth = iter + 1.0 - log2(log2(zmod))\n        escape[i, j] = log(max(smooth, 1.0))\n    else\n        escape[i, j] = NaN\n    end\nend\n\n# Figure\nfig = Figure(\n    size            = (1600, 900),\n    fontsize        = 14,\n    backgroundcolor = PAGE_BG,\n)\n\nax = Axis(\n    fig[1, 1];\n    title              = \"heatmap-mandelbrot · julia · makie · anyplot.ai\",\n    titlesize          = 20,\n    titlecolor         = INK,\n    xlabel             = \"Re(c)\",\n    ylabel             = \"Im(c)\",\n    xlabelsize         = 14,\n    ylabelsize         = 14,\n    xlabelcolor        = INK,\n    ylabelcolor        = INK,\n    xticklabelsize     = 12,\n    yticklabelsize     = 12,\n    xticklabelcolor    = INK_SOFT,\n    yticklabelcolor    = INK_SOFT,\n    xtickcolor         = INK_SOFT,\n    ytickcolor         = INK_SOFT,\n    leftspinecolor     = INK_SOFT,\n    bottomspinecolor   = INK_SOFT,\n    topspinevisible    = false,\n    rightspinevisible  = false,\n    xgridvisible       = false,\n    ygridvisible       = false,\n    backgroundcolor    = PAGE_BG,\n    aspect             = DataAspect(),\n)\n\nhm = heatmap!(ax, xs, ys, escape;\n    colormap   = ANYPLOT_SEQ_FIELDS,\n    nan_color  = INTERIOR_COLOR,\n    colorrange = (log(first(TICK_COUNTS)), log(last(TICK_COUNTS))),\n)\n\ncolsize!(fig.layout, 1, Aspect(1, (X_MAX - X_MIN) / (Y_MAX - Y_MIN)))\n\nColorbar(fig[1, 2], hm;\n    label          = \"Smoothed escape iteration (log scale)\",\n    ticks          = (log.(TICK_COUNTS), string.(TICK_COUNTS)),\n    labelsize      = 12,\n    labelcolor     = INK,\n    ticklabelsize  = 12,\n    ticklabelcolor = INK_SOFT,\n    tickcolor      = INK_SOFT,\n    width          = 16,\n)\n\nsave(\"plot-$(THEME).png\", fig; px_per_unit = 2)\n"}