{"spec_id":"barcode-code128","library":"makie","language":"julia","code":"# anyplot.ai\n# barcode-code128: Code 128 Barcode\n# Library: makie 0.21.9 | Julia 1.11.9\n# Quality: 92/100 | Created: 2026-09-01\n\nusing CairoMakie\nusing Colors\n\n# --- Theme tokens ------------------------------------------------------------\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\"\nconst INK_MUTED = THEME == \"light\" ? colorant\"#6B6A63\" : colorant\"#A8A79F\"\n\n# A printed barcode label is black ink on white stock under any lighting —\n# it does not follow the page theme the way surrounding chrome does, so\n# these two stay fixed instead of branching on THEME.\nconst LABEL_BG = colorant\"#FFFFFF\"\nconst BAR_INK  = colorant\"#0A0A0A\"\nconst LABEL_INK = colorant\"#1A1A17\"\n\n# Imprint brand accent — a data-palette color, so it stays fixed across themes.\nconst ACCENT = colorant\"#009E73\"\n\n# --- Data: Code 128 Subset B encoding -----------------------------------------\n# Laboratory specimen tracking label.\ncontent = \"SPEC-88451-QC\"\n\n# Subset B covers ASCII 32 (space) through 127 (DEL) as symbol values 0-95,\n# i.e. symbol value = character code point - 32. This spans every printable\n# character, so subset B alone can encode the full label without switching.\nvalues = [Int(c) - 32 for c in content]\n\nstart_value = 104  # Start Code B\nchecksum = mod(start_value + sum(v * i for (i, v) in enumerate(values)), 103)\ncodewords = vcat([start_value], values, [checksum], [106])  # 106 = Stop\n\n# Bar/space module-width patterns (ISO/IEC 15417) for symbol values 0-105 —\n# 6 widths each, alternating bar/space starting with a bar. Index 106 is the\n# unique 13-module Stop pattern (7 widths, also starting with a bar).\nconst CODE128_WIDTHS = [\n    [2,1,2,2,2,2], [2,2,2,1,2,2], [2,2,2,2,2,1], [1,2,1,2,2,3], [1,2,1,3,2,2],\n    [1,3,1,2,2,2], [1,2,2,2,1,3], [1,2,2,3,1,2], [1,3,2,2,1,2], [2,2,1,2,1,3],\n    [2,2,1,3,1,2], [2,3,1,2,1,2], [1,1,2,2,3,2], [1,2,2,1,3,2], [1,2,2,2,3,1],\n    [1,1,3,2,2,2], [1,2,3,1,2,2], [1,2,3,2,2,1], [2,2,3,2,1,1], [2,2,1,1,3,2],\n    [2,2,1,2,3,1], [2,1,3,2,1,2], [2,2,3,1,1,2], [3,1,2,1,3,1], [3,1,1,2,2,2],\n    [3,2,1,1,2,2], [3,2,1,2,2,1], [3,1,2,2,1,2], [3,2,2,1,1,2], [3,2,2,2,1,1],\n    [2,1,2,1,2,3], [2,1,2,3,2,1], [2,3,2,1,2,1], [1,1,1,3,2,3], [1,3,1,1,2,3],\n    [1,3,1,3,2,1], [1,1,2,3,1,3], [1,3,2,1,1,3], [1,3,2,3,1,1], [2,1,1,3,1,3],\n    [2,3,1,1,1,3], [2,3,1,3,1,1], [1,1,2,1,3,3], [1,1,2,3,3,1], [1,3,2,1,3,1],\n    [1,1,3,1,2,3], [1,1,3,3,2,1], [1,3,3,1,2,1], [3,1,3,1,2,1], [2,1,1,3,3,1],\n    [2,3,1,1,3,1], [2,1,3,1,1,3], [2,1,3,3,1,1], [2,1,3,1,3,1], [3,1,1,1,2,3],\n    [3,1,1,3,2,1], [3,3,1,1,2,1], [3,1,2,1,1,3], [3,1,2,3,1,1], [3,3,2,1,1,1],\n    [3,1,4,1,1,1], [2,2,1,4,1,1], [4,3,1,1,1,1], [1,1,1,2,2,4], [1,1,1,4,2,2],\n    [1,2,1,1,2,4], [1,2,1,4,2,1], [1,4,1,1,2,2], [1,4,1,2,2,1], [1,1,2,2,1,4],\n    [1,1,2,4,1,2], [1,2,2,1,1,4], [1,2,2,4,1,1], [1,4,2,1,1,2], [1,4,2,2,1,1],\n    [2,4,1,2,1,1], [2,2,1,1,1,4], [4,1,3,1,1,1], [2,4,1,1,1,2], [1,3,4,1,1,1],\n    [1,1,1,2,4,2], [1,2,1,1,4,2], [1,2,1,2,4,1], [1,1,4,2,1,2], [1,2,4,1,1,2],\n    [1,2,4,2,1,1], [4,1,1,2,1,2], [4,2,1,1,1,2], [4,2,1,2,1,1], [2,1,2,1,4,1],\n    [2,1,4,1,2,1], [4,1,2,1,2,1], [1,1,1,1,4,3], [1,1,1,3,4,1], [1,3,1,1,4,1],\n    [1,1,4,1,1,3], [1,1,4,3,1,1], [4,1,1,1,1,3], [4,1,1,3,1,1], [1,1,3,1,4,1],\n    [1,1,4,1,3,1], [3,1,1,1,4,1], [4,1,1,1,3,1], [2,1,1,4,1,2], [2,1,1,2,1,4],\n    [2,1,1,2,3,2],\n    [2,3,3,1,1,1,2],\n]\n\n# --- Geometry ------------------------------------------------------------------\nmodule_width  = 6    # design px per module\nquiet_modules = 10   # ISO/IEC 15417 minimum quiet zone, each side\n\nbar_widths  = [CODE128_WIDTHS[c + 1] for c in codewords]  # +1: Julia is 1-indexed\nflat_widths = vcat(bar_widths...) .* module_width\nis_bar      = vcat([isodd.(1:length(w)) for w in bar_widths]...)\n\nbarcode_width = sum(flat_widths)\nquiet_width   = quiet_modules * module_width\nhalf_block    = barcode_width / 2 + quiet_width\ncanvas_center = 800.0\n\nblock_left = canvas_center - half_block\nbar_x0     = block_left + quiet_width\n\nedges       = cumsum(vcat([0.0], flat_widths))\nbar_starts  = edges[1:end-1][is_bar] .+ bar_x0\nbar_lengths = flat_widths[is_bar]\n\nbar_y_bottom = 357.5\nbar_height   = 260.0\nbar_rects    = Rect2f.(bar_starts, bar_y_bottom, bar_lengths, bar_height)\n\ncard_pad_x  = 60.0\ncard_x      = block_left - card_pad_x\ncard_width  = 2 * half_block + 2 * card_pad_x\ncard_y      = 267.5\ncard_height = 400.0\n\n# --- Plot ------------------------------------------------------------------\nfig = Figure(size = (1600, 900), backgroundcolor = PAGE_BG)\n\nax = Axis(fig[1, 1]; backgroundcolor = PAGE_BG, aspect = DataAspect())\nhidedecorations!(ax)\nhidespines!(ax)\nxlims!(ax, 0, 1600)\nylims!(ax, 0, 900)\n\npoly!(ax, Rect2f(card_x, card_y, card_width, card_height); color = LABEL_BG)\npoly!(ax, bar_rects; color = BAR_INK)\n\ntext!(ax, canvas_center, 782.5;\n      text = \"barcode-code128 · julia · makie · anyplot.ai\",\n      color = INK, fontsize = 30, align = (:center, :center))\ntext!(ax, canvas_center, 725.5;\n      text = \"Laboratory specimen label\",\n      color = INK_SOFT, fontsize = 18, align = (:center, :center))\n\n# Brand accent between the subtitle and the card — a small polish touch\n# that never touches the black-ink-on-white barcode itself.\npoly!(ax, Rect2f(canvas_center - 55, 693.5, 110, 4); color = ACCENT)\n\ntext!(ax, canvas_center, 307.5; text = content,\n      color = LABEL_INK, fontsize = 26, font = :bold, align = (:center, :center))\ntext!(ax, canvas_center, 117.5;\n      text = \"Code 128, Subset B  ·  Quiet zone $(quiet_modules) modules each side  ·  Check digit $(checksum)\",\n      color = INK_MUTED, fontsize = 15, align = (:center, :center))\n\n# --- Save ------------------------------------------------------------------\nsave(\"plot-$(THEME).png\", fig; px_per_unit = 2)\n"}